/[MITgcm]/MITgcm/model/src/dynamics.F
ViewVC logotype

Diff of /MITgcm/model/src/dynamics.F

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

revision 1.19 by cnh, Mon Jun 15 05:13:56 1998 UTC revision 1.54.2.3 by adcroft, Tue Jan 9 14:39:34 2001 UTC
# Line 1  Line 1 
1  C $Header$  C $Header$
2    
3  #include "CPP_EEOPTIONS.h"  #include "CPP_OPTIONS.h"
4    
5        SUBROUTINE DYNAMICS(myTime, myIter, myThid)        SUBROUTINE DYNAMICS(myTime, myIter, myThid)
6  C     /==========================================================\  C     /==========================================================\
# Line 20  C     | ===== Line 20  C     | =====
20  C     | C*P* comments indicating place holders for which code is |  C     | C*P* comments indicating place holders for which code is |
21  C     |      presently being developed.                          |  C     |      presently being developed.                          |
22  C     \==========================================================/  C     \==========================================================/
23          IMPLICIT NONE
24    
25  C     == Global variables ===  C     == Global variables ===
26  #include "SIZE.h"  #include "SIZE.h"
# Line 27  C     == Global variables === Line 28  C     == Global variables ===
28  #include "CG2D.h"  #include "CG2D.h"
29  #include "PARAMS.h"  #include "PARAMS.h"
30  #include "DYNVARS.h"  #include "DYNVARS.h"
31    #include "GRID.h"
32    
33    #ifdef ALLOW_AUTODIFF_TAMC
34    # include "tamc.h"
35    # include "tamc_keys.h"
36    #endif /* ALLOW_AUTODIFF_TAMC */
37    
38    #ifdef ALLOW_KPP
39    # include "KPP.h"
40    #endif
41    
42  C     == Routine arguments ==  C     == Routine arguments ==
43  C     myTime - Current time in simulation  C     myTime - Current time in simulation
44  C     myIter - Current iteration number in simulation  C     myIter - Current iteration number in simulation
45  C     myThid - Thread number for this instance of the routine.  C     myThid - Thread number for this instance of the routine.
       INTEGER myThid  
46        _RL myTime        _RL myTime
47        INTEGER myIter        INTEGER myIter
48          INTEGER myThid
49    
50  C     == Local variables  C     == Local variables
51  C     xA, yA                 - Per block temporaries holding face areas  C     xA, yA                 - Per block temporaries holding face areas
52  C     uTrans, vTrans, wTrans - Per block temporaries holding flow transport  C     uTrans, vTrans, rTrans - Per block temporaries holding flow
53  C     wVel                     o uTrans: Zonal transport  C                              transport
54    C     rVel                     o uTrans: Zonal transport
55  C                              o vTrans: Meridional transport  C                              o vTrans: Meridional transport
56  C                              o wTrans: Vertical transport  C                              o rTrans: Vertical transport
57  C                              o wVel:   Vertical velocity at upper and lower  C                              o rVel:   Vertical velocity at upper and
58  C                                        cell faces.  C                                        lower cell faces.
59  C     maskC,maskUp             o maskC: land/water mask for tracer cells  C     maskC,maskUp             o maskC: land/water mask for tracer cells
60  C                              o maskUp: land/water mask for W points  C                              o maskUp: land/water mask for W points
61  C     aTerm, xTerm, cTerm    - Work arrays for holding separate terms in  C     aTerm, xTerm, cTerm    - Work arrays for holding separate terms in
# Line 59  C                              o fVer: V Line 71  C                              o fVer: V
71  C                                      is "pipelined" in the vertical  C                                      is "pipelined" in the vertical
72  C                                      so we need an fVer for each  C                                      so we need an fVer for each
73  C                                      variable.  C                                      variable.
74  C     iMin, iMax - Ranges and sub-block indices on which calculations  C     rhoK, rhoKM1   - Density at current level, level above and level
75  C     jMin, jMax   are applied.  C                      below.
76    C     rhoKP1                                                                  
77    C     buoyK, buoyKM1 - Buoyancy at current level and level above.
78    C     phiHyd         - Hydrostatic part of the potential phiHydi.
79    C                      In z coords phiHydiHyd is the hydrostatic
80    C                      pressure anomaly
81    C                      In p coords phiHydiHyd is the geopotential
82    C                      surface height
83    C                      anomaly.
84    C     etaSurfX,      - Holds surface elevation gradient in X and Y.
85    C     etaSurfY
86    C     KappaRT,       - Total diffusion in vertical for T and S.
87    C     KappaRS          (background + spatially varying, isopycnal term).
88    C     iMin, iMax     - Ranges and sub-block indices on which calculations
89    C     jMin, jMax       are applied.
90  C     bi, bj  C     bi, bj
91  C     k, kUp, kDown, kM1 - Index for layer above and below. kUp and kDown  C     k, kup,        - Index for layer above and below. kup and kDown
92  C                          are switched with layer to be the appropriate index  C     kDown, km1       are switched with layer to be the appropriate
93  C                          into fVerTerm  C                      index into fVerTerm.
94        _RS xA    (1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RS xA      (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
95        _RS yA    (1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RS yA      (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
96        _RL uTrans(1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RL uTrans  (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
97        _RL vTrans(1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RL vTrans  (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
98        _RL wTrans(1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RL rTrans  (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
99        _RL wVel  (1-OLx:sNx+OLx,1-OLy:sNy+OLy,2)        _RL rVel    (1-OLx:sNx+OLx,1-OLy:sNy+OLy,2)
100        _RS maskC (1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RS maskC   (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
101        _RS maskUp(1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RS maskUp  (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
102        _RL aTerm (1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RL aTerm   (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
103        _RL xTerm (1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RL xTerm   (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
104        _RL cTerm (1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RL cTerm   (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
105        _RL mTerm (1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RL mTerm   (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
106        _RL pTerm (1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RL pTerm   (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
107        _RL fZon  (1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RL fZon    (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
108        _RL fMer  (1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RL fMer    (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
109        _RL fVerT (1-OLx:sNx+OLx,1-OLy:sNy+OLy,2)        _RL fVerT   (1-OLx:sNx+OLx,1-OLy:sNy+OLy,2)
110        _RL fVerS (1-OLx:sNx+OLx,1-OLy:sNy+OLy,2)        _RL fVerS   (1-OLx:sNx+OLx,1-OLy:sNy+OLy,2)
111        _RL fVerU (1-OLx:sNx+OLx,1-OLy:sNy+OLy,2)        _RL fVerU   (1-OLx:sNx+OLx,1-OLy:sNy+OLy,2)
112        _RL fVerV (1-OLx:sNx+OLx,1-OLy:sNy+OLy,2)        _RL fVerV   (1-OLx:sNx+OLx,1-OLy:sNy+OLy,2)
113        _RL pH    (1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nz)        _RL phiHyd  (1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr)
114        _RL rhokm1(1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RL rhokm1  (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
115        _RL rhokp1(1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RL rhokp1  (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
116        _RL rhok  (1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RL rhok    (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
117        _RL rhotmp(1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RL buoyKM1 (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
118        _RL pSurfX(1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RL buoyK   (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
119        _RL pSurfY(1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RL rhotmp  (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
120        _RL K13   (1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nz)        _RL KappaRT (1-Olx:sNx+Olx,1-Oly:sNy+Oly,Nr)
121        _RL K23   (1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nz)        _RL KappaRS (1-Olx:sNx+Olx,1-Oly:sNy+Oly,Nr)
122        _RL K33   (1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nz)        _RL KappaRU (1-Olx:sNx+Olx,1-Oly:sNy+Oly,Nr)
123        _RL KapGM (1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RL KappaRV (1-Olx:sNx+Olx,1-Oly:sNy+Oly,Nr)
124        _RL KappaZT(1-Olx:sNx+Olx,1-Oly:sNy+Oly,Nz)        _RL sigmaX  (1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr)
125        _RL KappaZS(1-Olx:sNx+Olx,1-Oly:sNy+Oly,Nz)        _RL sigmaY  (1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr)
126          _RL sigmaR  (1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr)
127    
128    C This is currently also used by IVDC and Diagnostics
129    C #ifdef INCLUDE_CONVECT_CALL
130          _RL ConvectCount (1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr)
131    C #endif
132    
133        INTEGER iMin, iMax        INTEGER iMin, iMax
134        INTEGER jMin, jMax        INTEGER jMin, jMax
135        INTEGER bi, bj        INTEGER bi, bj
136        INTEGER i, j        INTEGER i, j
137        INTEGER k, kM1, kUp, kDown        INTEGER k, km1, kup, kDown
138        LOGICAL BOTTOM_LAYER  
139    #ifdef ALLOW_AUTODIFF_TAMC
140          INTEGER    isbyte
141          PARAMETER( isbyte = 4 )
142    
143          INTEGER act1, act2, act3, act4
144          INTEGER max1, max2, max3
145          INTEGER iikey, kkey
146          INTEGER maximpl
147    #endif /* ALLOW_AUTODIFF_TAMC */
148    
149  C---    The algorithm...  C---    The algorithm...
150  C  C
# Line 119  C       "Calculation of Gs" Line 160  C       "Calculation of Gs"
160  C       ===================  C       ===================
161  C       This is where all the accelerations and tendencies (ie.  C       This is where all the accelerations and tendencies (ie.
162  C       physics, parameterizations etc...) are calculated  C       physics, parameterizations etc...) are calculated
163  C         w = sum_z ( div. u[n] )  C         rVel = sum_r ( div. u[n] )
164  C         rho = rho ( theta[n], salt[n] )  C         rho = rho ( theta[n], salt[n] )
165    C         b   = b(rho, theta)
166  C         K31 = K31 ( rho )  C         K31 = K31 ( rho )
167  C         Gu[n] = Gu( u[n], v[n], w, rho, Ph, ... )  C         Gu[n] = Gu( u[n], v[n], rVel, b, ... )
168  C         Gv[n] = Gv( u[n], v[n], w, rho, Ph, ... )  C         Gv[n] = Gv( u[n], v[n], rVel, b, ... )
169  C         Gt[n] = Gt( theta[n], u[n], v[n], w, K31, ... )  C         Gt[n] = Gt( theta[n], u[n], v[n], rVel, K31, ... )
170  C         Gs[n] = Gs( salt[n], u[n], v[n], w, K31, ... )  C         Gs[n] = Gs( salt[n], u[n], v[n], rVel, K31, ... )
171  C  C
172  C       "Time-stepping" or "Prediction"  C       "Time-stepping" or "Prediction"
173  C       ================================  C       ================================
# Line 149  C         (1 + dt * K * d_zz) theta[n] = Line 191  C         (1 + dt * K * d_zz) theta[n] =
191  C         (1 + dt * K * d_zz) salt[n] = salt*  C         (1 + dt * K * d_zz) salt[n] = salt*
192  C---  C---
193    
194    #ifdef ALLOW_AUTODIFF_TAMC
195    C--   dummy statement to end declaration part
196          ikey = 1
197    #endif /* ALLOW_AUTODIFF_TAMC */
198    
199  C--   Set up work arrays with valid (i.e. not NaN) values  C--   Set up work arrays with valid (i.e. not NaN) values
200  C     These inital values do not alter the numerical results. They  C     These inital values do not alter the numerical results. They
201  C     just ensure that all memory references are to valid floating  C     just ensure that all memory references are to valid floating
# Line 167  C     uninitialised but inert locations. Line 214  C     uninitialised but inert locations.
214          pTerm(i,j)   = 0. _d 0          pTerm(i,j)   = 0. _d 0
215          fZon(i,j)    = 0. _d 0          fZon(i,j)    = 0. _d 0
216          fMer(i,j)    = 0. _d 0          fMer(i,j)    = 0. _d 0
217          DO K=1,nZ          DO k=1,Nr
218           pH (i,j,k)  = 0. _d 0           phiHyd (i,j,k)  = 0. _d 0
219           K13(i,j,k) = 0. _d 0           KappaRU(i,j,k) = 0. _d 0
220           K23(i,j,k) = 0. _d 0           KappaRV(i,j,k) = 0. _d 0
221           K33(i,j,k) = 0. _d 0           sigmaX(i,j,k) = 0. _d 0
222           KappaZT(i,j,k) = 0. _d 0           sigmaY(i,j,k) = 0. _d 0
223             sigmaR(i,j,k) = 0. _d 0
224          ENDDO          ENDDO
225          rhokm1(i,j)  = 0. _d 0          rhoKM1 (i,j) = 0. _d 0
226          rhok  (i,j)  = 0. _d 0          rhok   (i,j) = 0. _d 0
227          rhokp1(i,j)  = 0. _d 0          rhoKP1 (i,j) = 0. _d 0
228          rhotmp(i,j)  = 0. _d 0          rhoTMP (i,j) = 0. _d 0
229          maskC (i,j)  = 0. _d 0          buoyKM1(i,j) = 0. _d 0
230            buoyK  (i,j) = 0. _d 0
231            maskC  (i,j) = 0. _d 0
232         ENDDO         ENDDO
233        ENDDO        ENDDO
234    
235    
236    #ifdef ALLOW_AUTODIFF_TAMC
237    C--   HPF directive to help TAMC
238    CHPF$ INDEPENDENT
239    #endif /* ALLOW_AUTODIFF_TAMC */
240    
241        DO bj=myByLo(myThid),myByHi(myThid)        DO bj=myByLo(myThid),myByHi(myThid)
242    
243    #ifdef ALLOW_AUTODIFF_TAMC
244    C--    HPF directive to help TAMC
245    CHPF$  INDEPENDENT, NEW (rTrans,rVel,fVerT,fVerS,fVerU,fVerV
246    CHPF$&                  ,phiHyd,utrans,vtrans,maskc,xA,yA
247    CHPF$&                  ,KappaRT,KappaRS,KappaRU,KappaRV
248    CHPF$&                  )
249    #endif /* ALLOW_AUTODIFF_TAMC */
250    
251         DO bi=myBxLo(myThid),myBxHi(myThid)         DO bi=myBxLo(myThid),myBxHi(myThid)
252    
253    #ifdef ALLOW_AUTODIFF_TAMC
254              act1 = bi - myBxLo(myThid)
255              max1 = myBxHi(myThid) - myBxLo(myThid) + 1
256    
257              act2 = bj - myByLo(myThid)
258              max2 = myByHi(myThid) - myByLo(myThid) + 1
259    
260              act3 = myThid - 1
261              max3 = nTx*nTy
262    
263              act4 = ikey_dynamics - 1
264    
265              ikey = (act1 + 1) + act2*max1
266         &                      + act3*max1*max2
267         &                      + act4*max1*max2*max3
268    #endif /* ALLOW_AUTODIFF_TAMC */
269    
270  C--     Set up work arrays that need valid initial values  C--     Set up work arrays that need valid initial values
271          DO j=1-OLy,sNy+OLy          DO j=1-OLy,sNy+OLy
272           DO i=1-OLx,sNx+OLx           DO i=1-OLx,sNx+OLx
273            wTrans(i,j)  = 0. _d 0            rTrans(i,j)   = 0. _d 0
274            wVel  (i,j,1) = 0. _d 0            rVel  (i,j,1) = 0. _d 0
275            wVel  (i,j,2) = 0. _d 0            rVel  (i,j,2) = 0. _d 0
276            fVerT(i,j,1) = 0. _d 0            fVerT (i,j,1) = 0. _d 0
277            fVerT(i,j,2) = 0. _d 0            fVerT (i,j,2) = 0. _d 0
278            fVerS(i,j,1) = 0. _d 0            fVerS (i,j,1) = 0. _d 0
279            fVerS(i,j,2) = 0. _d 0            fVerS (i,j,2) = 0. _d 0
280            fVerU(i,j,1) = 0. _d 0            fVerU (i,j,1) = 0. _d 0
281            fVerU(i,j,2) = 0. _d 0            fVerU (i,j,2) = 0. _d 0
282            fVerV(i,j,1) = 0. _d 0            fVerV (i,j,1) = 0. _d 0
283            fVerV(i,j,2) = 0. _d 0            fVerV (i,j,2) = 0. _d 0
284            pH(i,j,1) = 0. _d 0            phiHyd(i,j,1) = 0. _d 0
285            K13(i,j,1) = 0. _d 0           ENDDO
286            K23(i,j,1) = 0. _d 0          ENDDO
287            K33(i,j,1) = 0. _d 0  
288            KapGM(i,j) = 0. _d 0          DO k=1,Nr
289             DO j=1-OLy,sNy+OLy
290              DO i=1-OLx,sNx+OLx
291    #ifdef INCLUDE_CONVECT_CALL
292               ConvectCount(i,j,k) = 0.
293    #endif
294               KappaRT(i,j,k) = 0. _d 0
295               KappaRS(i,j,k) = 0. _d 0
296              ENDDO
297           ENDDO           ENDDO
298          ENDDO          ENDDO
299    
# Line 212  C--     Set up work arrays that need val Line 302  C--     Set up work arrays that need val
302          jMin = 1-OLy+1          jMin = 1-OLy+1
303          jMax = sNy+OLy          jMax = sNy+OLy
304    
         K = 1  
         BOTTOM_LAYER = K .EQ. Nz  
305    
306  C--     Calculate gradient of surface pressure  C--     Start of diagnostic loop
307          CALL GRAD_PSURF(          DO k=Nr,1,-1
      I       bi,bj,iMin,iMax,jMin,jMax,  
      O       pSurfX,pSurfY,  
      I       myThid)  
   
 C--     Update fields in top level according to tendency terms  
         CALL CORRECTION_STEP(  
      I       bi,bj,iMin,iMax,jMin,jMax,K,pSurfX,pSurfY,myThid)  
   
 C--     Density of 1st level (below W(1)) reference to level 1  
         CALL FIND_RHO(  
      I     bi, bj, iMin, iMax, jMin, jMax, K, K, eosType,  
      O     rhoKm1,  
      I     myThid )  
   
         IF ( .NOT. BOTTOM_LAYER ) THEN  
 C--      Check static stability with layer below  
 C        and mix as needed.  
          CALL FIND_RHO(  
      I      bi, bj, iMin, iMax, jMin, jMax, K+1, K, eosType,  
      O      rhoKp1,  
      I      myThid )  
          CALL CONVECT(  
      I       bi,bj,iMin,iMax,jMin,jMax,K+1,rhoKm1,rhoKp1,  
      I       myTime,myIter,myThid)  
 C--      Recompute density after mixing  
          CALL FIND_RHO(  
      I      bi, bj, iMin, iMax, jMin, jMax, K, K, eosType,  
      O      rhoKm1,  
      I      myThid )  
         ENDIF  
308    
309  C--     Integrate hydrostatic balance for pH with BC of pH(z=0)=0  #ifdef ALLOW_AUTODIFF_TAMC
310          CALL CALC_PH(  C? Patrick, is this formula correct now that we change the loop range?
311       I      bi,bj,iMin,iMax,jMin,jMax,K,rhoKm1,rhoKm1,  C? Do we still need this?
312       U      pH,           kkey = (ikey-1)*(Nr-2+1) + (k-2) + 1
313       I      myThid )  #endif /* ALLOW_AUTODIFF_TAMC */
314    
315          DO K=2,Nz  #ifdef ALLOW_OBCS
316    C--       Calculate future values on open boundaries
317           BOTTOM_LAYER = K .EQ. Nz            IF (openBoundaries) THEN
318    Caja        CALL CYCLE_OBCS( k, bi, bj, myThid )
319  C--      Update fields in Kth level according to tendency terms  c new args! CALL SET_OBCS( k, bi, bj, myTime, myThid )
320           CALL CORRECTION_STEP(  c +deltaT?
321       I        bi,bj,iMin,iMax,jMin,jMax,K,pSurfX,pSurfY,myThid)            ENDIF
322  C--      Density of K level (below W(K)) reference to K level  #endif
323           CALL FIND_RHO(  
324       I      bi, bj, iMin, iMax, jMin, jMax,  K, K, eosType,  C--       Integrate continuity vertically for vertical velocity
325       O      rhoK,            CALL INTEGRATE_FOR_W(
326       I      myThid )       I                         bi, bj, k, uVel, vVel,
327           IF ( .NOT. BOTTOM_LAYER ) THEN       O                         wVel,
328  C--       Check static stability with layer below       I                         myThid )
329  C         and mix as needed.  #ifdef ALLOW_OBCS
330  C--       Density of K+1 level (below W(K+1)) reference to K level            IF (openBoundaries) THEN
331            CALL FIND_RHO(  c new subr  CALL OBCS_APPLY_W( bi, bj, k, wVel, myThid )
332       I       bi, bj, iMin, iMax, jMin, jMax,  K+1, K, eosType,            ENDIF
333       O       rhoKp1,  #endif
334       I       myThid )  
335            CALL CONVECT(  C--       Calculate gradients of potential density for isoneutral
336       I        bi,bj,iMin,iMax,jMin,jMax,K+1,rhoK,rhoKp1,  C         slope terms (e.g. GM/Redi tensor or IVDC diffusivity)
337       I        myTime,myIter,myThid)            IF ( k.GT.1 .AND. (useGMRedi.OR.ivdc_kappa.NE.0.) ) THEN
338  C--       Recompute density after mixing              CALL FIND_RHO(
339            CALL FIND_RHO(       I        bi, bj, iMin, iMax, jMin, jMax, k, k, eosType,
340       I       bi, bj, iMin, iMax, jMin, jMax, K, K, eosType,       O        rhoK,
341       O       rhoK,       I        myThid )
342       I       myThid )              CALL FIND_RHO(
343           ENDIF       I        bi, bj, iMin, iMax, jMin, jMax, k-1, k, eosType,
344  C--      Integrate hydrostatic balance for pH with BC of pH(z=0)=0       O        rhoKm1,
345           CALL CALC_PH(       I        myThid )
346       I       bi,bj,iMin,iMax,jMin,jMax,K,rhoKm1,rhoK,              CALL GRAD_SIGMA(
347       U       pH,       I             bi, bj, iMin, iMax, jMin, jMax, k,
348       I       myThid )       I             rhoK, rhoKm1, rhoK,
349  C--      Calculate iso-neutral slopes for the GM/Redi parameterisation       O             sigmaX, sigmaY, sigmaR,
350           CALL FIND_RHO(       I             myThid )
351       I      bi, bj, iMin, iMax, jMin, jMax, K-1, K, eosType,            ENDIF
352       O      rhoTmp,  
353       I      myThid )  C--       Implicit Vertical Diffusion for Convection
354           CALL CALC_ISOSLOPES(            IF (k.GT.1 .AND. ivdc_kappa.NE.0.) THEN
355       I             bi, bj, iMin, iMax, jMin, jMax, K,              CALL CALC_IVDC(
356       I             rhoKm1, rhoK, rhotmp,       I        bi, bj, iMin, iMax, jMin, jMax, k,
357       O             K13, K23, K33, KapGM,       I        rhoKm1, rhoK,
358    c should use sigmaR !!!
359         U        ConvectCount, KappaRT, KappaRS,
360         I        myTime, myIter, myThid)
361              END IF
362    
363    C--     end of diagnostic k loop (Nr:1)
364            ENDDO
365    
366    #ifdef  ALLOW_GMREDI
367    C--     Calculate iso-neutral slopes for the GM/Redi parameterisation
368            IF (useGMRedi) THEN
369              DO k=1,Nr
370                CALL GMREDI_CALC_TENSOR(
371         I             bi, bj, iMin, iMax, jMin, jMax, k,
372         I             sigmaX, sigmaY, sigmaR,
373       I             myThid )       I             myThid )
          DO J=jMin,jMax  
           DO I=iMin,iMax  
            rhoKm1(I,J)=rhoK(I,J)  
374            ENDDO            ENDDO
375           ENDDO          ENDIF
376    #endif  /* ALLOW_GMREDI */
377    
378    #ifdef  ALLOW_KPP
379    C--     Compute KPP mixing coefficients
380            IF (useKPP) THEN
381              CALL KPP_CALC(
382         I                  bi, bj, myTime, myThid )
383            ENDIF
384    #endif  /* ALLOW_KPP */
385    
386          ENDDO ! K  C--     Determines forcing terms based on external fields
387    C       relaxation terms, etc.
388            CALL EXTERNAL_FORCING_SURF(
389         I             bi, bj, iMin, iMax, jMin, jMax,
390         I             myThid )
391    
392          DO K = Nz, 1, -1  #ifdef ALLOW_AUTODIFF_TAMC
393           kM1  =max(1,k-1)   ! Points to level above k (=k-1)  CADJ STORE KappaRT(:,:,:)     = comlev1_bibj, key = ikey, byte = isbyte
394           kUp  =1+MOD(k+1,2) ! Cycles through 1,2 to point to layer above  CADJ STORE KappaRS(:,:,:)     = comlev1_bibj, key = ikey, byte = isbyte
395           kDown=1+MOD(k,2)   ! Cycles through 2,1 to point to current layer  CADJ STORE theta(:,:,:,bi,bj) = comlev1_bibj, key = ikey, byte = isbyte
396           iMin = 1-OLx+2  CADJ STORE salt (:,:,:,bi,bj) = comlev1_bibj, key = ikey, byte = isbyte
397           iMax = sNx+OLx-1  CADJ STORE uvel (:,:,:,bi,bj) = comlev1_bibj, key = ikey, byte = isbyte
398           jMin = 1-OLy+2  CADJ STORE vvel (:,:,:,bi,bj) = comlev1_bibj, key = ikey, byte = isbyte
399           jMax = sNy+OLy-1  #endif /* ALLOW_AUTODIFF_TAMC */
400    
401    
402    C--     Start of thermodynamics loop
403            DO k=Nr,1,-1
404    
405    C--       km1    Points to level above k (=k-1)
406    C--       kup    Cycles through 1,2 to point to layer above
407    C--       kDown  Cycles through 2,1 to point to current layer
408    
409              km1  = MAX(1,k-1)
410              kup  = 1+MOD(k+1,2)
411              kDown= 1+MOD(k,2)
412    
413              iMin = 1-OLx+2
414              iMax = sNx+OLx-1
415              jMin = 1-OLy+2
416              jMax = sNy+OLy-1
417    
418    #ifdef ALLOW_AUTODIFF_TAMC
419    CPatrick Is this formula correct?
420             kkey = (ikey-1)*(Nr-1+1) + (k-1) + 1
421    CADJ STORE rvel  (:,:,kDown) = comlev1_bibj_k, key = kkey, byte = isbyte
422    CADJ STORE rTrans(:,:)       = comlev1_bibj_k, key = kkey, byte = isbyte
423    CADJ STORE KappaRT(:,:,:)    = comlev1_bibj_k, key = kkey, byte = isbyte
424    CADJ STORE KappaRS(:,:,:)    = comlev1_bibj_k, key = kkey, byte = isbyte
425    #endif /* ALLOW_AUTODIFF_TAMC */
426    
427  C--      Get temporary terms used by tendency routines  C--      Get temporary terms used by tendency routines
428           CALL CALC_COMMON_FACTORS (           CALL CALC_COMMON_FACTORS (
429       I        bi,bj,iMin,iMax,jMin,jMax,k,kM1,kUp,kDown,       I        bi,bj,iMin,iMax,jMin,jMax,k,km1,kup,kDown,
430       O        xA,yA,uTrans,vTrans,wTrans,wVel,maskC,maskUp,       O        xA,yA,uTrans,vTrans,rTrans,rVel,maskC,maskUp,
431       I        myThid)       I        myThid)
432    
433    #ifdef  INCLUDE_CALC_DIFFUSIVITY_CALL
434  C--      Calculate the total vertical diffusivity  C--      Calculate the total vertical diffusivity
435           CALL CALC_DIFFUSIVITY(           CALL CALC_DIFFUSIVITY(
436       I        bi,bj,iMin,iMax,jMin,jMax,K,       I        bi,bj,iMin,iMax,jMin,jMax,k,
437       I        maskC,maskUp,KapGM,K33,       I        maskC,maskup,
438       O        KappaZT,KappaZS,       O        KappaRT,KappaRS,KappaRU,KappaRV,
439       I        myThid)       I        myThid)
440    #endif
441    
442  C--      Calculate accelerations in the momentum equations  C--      Calculate active tracer tendencies (gT,gS,...)
443           IF ( momStepping ) THEN  C        and step forward storing result in gTnm1, gSnm1, etc.
           CALL CALC_MOM_RHS(  
      I         bi,bj,iMin,iMax,jMin,jMax,k,kM1,kUp,kDown,  
      I         xA,yA,uTrans,vTrans,wTrans,wVel,maskC,  
      I         pH,  
      U         aTerm,xTerm,cTerm,mTerm,pTerm,  
      U         fZon, fMer, fVerU, fVerV,  
      I         myThid)  
          ENDIF  
   
 C--      Calculate active tracer tendencies  
444           IF ( tempStepping ) THEN           IF ( tempStepping ) THEN
445            CALL CALC_GT(             CALL CALC_GT(
446       I         bi,bj,iMin,iMax,jMin,jMax, k,kM1,kUp,kDown,       I         bi,bj,iMin,iMax,jMin,jMax, k,km1,kup,kDown,
447       I         xA,yA,uTrans,vTrans,wTrans,maskUp,       I         xA,yA,uTrans,vTrans,rTrans,maskUp,maskC,
448       I         K13,K23,KappaZT,KapGM,       I         KappaRT,
449       U         aTerm,xTerm,fZon,fMer,fVerT,       U         aTerm,xTerm,fZon,fMer,fVerT,
450       I         myThid)       I         myTime, myThid)
451               CALL TIMESTEP_TRACER(
452         I         bi,bj,iMin,iMax,jMin,jMax,k,
453         I         theta, gT,
454         U         gTnm1,
455         I         myIter, myThid)
456           ENDIF           ENDIF
457           IF ( saltStepping ) THEN           IF ( saltStepping ) THEN
458            CALL CALC_GS(             CALL CALC_GS(
459       I         bi,bj,iMin,iMax,jMin,jMax, k,kM1,kUp,kDown,       I         bi,bj,iMin,iMax,jMin,jMax, k,km1,kup,kDown,
460       I         xA,yA,uTrans,vTrans,wTrans,maskUp,       I         xA,yA,uTrans,vTrans,rTrans,maskUp,maskC,
461       I         K13,K23,KappaZS,KapGM,       I         KappaRS,
462       U         aTerm,xTerm,fZon,fMer,fVerS,       U         aTerm,xTerm,fZon,fMer,fVerS,
463       I         myThid)       I         myTime, myThid)
464               CALL TIMESTEP_TRACER(
465         I         bi,bj,iMin,iMax,jMin,jMax,k,
466         I         salt, gS,
467         U         gSnm1,
468         I         myIter, myThid)
469           ENDIF           ENDIF
470    #ifdef ALLOW_OBCS
471    C--      Apply open boundary conditions
472             IF (openBoundaries) THEN
473    #ifdef ALLOW_AUTODIFF_TAMC
474    CADJ STORE gwnm1(:,:,k,bi,bj) = comlev1_bibj_k
475    CADJ &   , key = kkey, byte = isbyte
476    #endif /* ALLOW_AUTODIFF_TAMC */
477    c new subr  CALL OBCS_APPLY_TS( bi, bj, k, myThid )
478             END IF
479    #endif
480    C--      Freeze water
481             IF (allowFreezing) THEN
482    #ifdef ALLOW_AUTODIFF_TAMC
483    CADJ STORE gTNm1(:,:,k,bi,bj) = comlev1_bibj_k
484    CADJ &   , key = kkey, byte = isbyte
485    #endif /* ALLOW_AUTODIFF_TAMC */
486                CALL FREEZE( bi, bj, iMin, iMax, jMin, jMax, k, myThid )
487             END IF
488    
489    C--     end of thermodynamic k loop (Nr:1)
490            ENDDO
491    
 C--      Prediction step (step forward all model variables)  
          CALL TIMESTEP(  
      I       bi,bj,iMin,iMax,jMin,jMax,K,  
      I       myThid)  
   
 C--      Diagnose barotropic divergence of predicted fields  
          CALL DIV_G(  
      I       bi,bj,iMin,iMax,jMin,jMax,K,  
      I       xA,yA,  
      I       myThid)  
492    
493          ENDDO ! K  #ifdef ALLOW_AUTODIFF_TAMC
494    CPatrick? What about this one?
495               maximpl = 6
496               iikey = (ikey-1)*maximpl
497    #endif /* ALLOW_AUTODIFF_TAMC */
498    
499  C--     Implicit diffusion  C--     Implicit diffusion
500          IF (implicitDiffusion) THEN          IF (implicitDiffusion) THEN
501           CALL IMPLDIFF( bi, bj, iMin, iMax, jMin, jMax,  
502       I                  KappaZT,KappaZS,            IF (tempStepping) THEN
503       I                  myThid )  #ifdef ALLOW_AUTODIFF_TAMC
504                idkey = iikey + 1
505    #endif /* ALLOW_AUTODIFF_TAMC */
506                CALL IMPLDIFF(
507         I         bi, bj, iMin, iMax, jMin, jMax,
508         I         deltaTtracer, KappaRT, recip_HFacC,
509         U         gTNm1,
510         I         myThid )
511             ENDIF
512    
513             IF (saltStepping) THEN
514    #ifdef ALLOW_AUTODIFF_TAMC
515             idkey = iikey + 2
516    #endif /* ALLOW_AUTODIFF_TAMC */
517                CALL IMPLDIFF(
518         I         bi, bj, iMin, iMax, jMin, jMax,
519         I         deltaTtracer, KappaRS, recip_HFacC,
520         U         gSNm1,
521         I         myThid )
522             ENDIF
523    
524    C--     End If implicitDiffusion
525            ENDIF
526    
527    C--     Start of dynamics loop
528            DO k=1,Nr
529    
530    C--       km1    Points to level above k (=k-1)
531    C--       kup    Cycles through 1,2 to point to layer above
532    C--       kDown  Cycles through 2,1 to point to current layer
533    
534              km1  = MAX(1,k-1)
535              kup  = 1+MOD(k+1,2)
536              kDown= 1+MOD(k,2)
537    
538              iMin = 1-OLx+2
539              iMax = sNx+OLx-1
540              jMin = 1-OLy+2
541              jMax = sNy+OLy-1
542    
543    C--      Calculate buoyancy
544             CALL FIND_RHO(
545         I        bi, bj, iMin, iMax, jMin, jMax, km1, km1, eosType,
546         O        rhoKm1,
547         I        myThid )
548             CALL CALC_BUOYANCY(
549         I        bi,bj,iMin,iMax,jMin,jMax,k,rhoKm1,
550         O        buoyKm1,
551         I        myThid )
552             CALL FIND_RHO(
553         I        bi, bj, iMin, iMax, jMin, jMax, k, k, eosType,
554         O        rhoK,
555         I        myThid )
556             CALL CALC_BUOYANCY(
557         I        bi,bj,iMin,iMax,jMin,jMax,k,rhoK,
558         O        buoyK,
559         I        myThid )
560    
561    C--      Integrate hydrostatic balance for phiHyd with BC of
562    C--      phiHyd(z=0)=0
563             CALL CALC_PHI_HYD(
564         I        bi,bj,iMin,iMax,jMin,jMax,k,buoyKm1,buoyK,
565         U        phiHyd,
566         I        myThid )
567    
568    C--      Get temporary terms used by tendency routines
569             CALL CALC_COMMON_FACTORS (
570         I        bi,bj,iMin,iMax,jMin,jMax,k,km1,kup,kDown,
571         O        xA,yA,uTrans,vTrans,rTrans,rVel,maskC,maskUp,
572         I        myThid)
573    
574    C--      Calculate accelerations in the momentum equations (gU, gV, ...)
575    C        and step forward storing the result in gUnm1, gVnm1, etc...
576             IF ( momStepping ) THEN
577               CALL CALC_MOM_RHS(
578         I         bi,bj,iMin,iMax,jMin,jMax,k,km1,kup,kDown,
579         I         xA,yA,uTrans,vTrans,maskC,
580         I         phiHyd,KappaRU,KappaRV,
581         U         fVerU, fVerV,
582         I         myTime, myThid)
583               CALL TIMESTEP(
584         I         bi,bj,iMin,iMax,jMin,jMax,k,
585         I         myIter, myThid)
586    #ifdef   ALLOW_AUTODIFF_TAMC
587    #ifdef   INCLUDE_CD_CODE
588             ELSE
589               DO j=1-OLy,sNy+OLy
590                 DO i=1-OLx,sNx+OLx
591                   guCD(i,j,k,bi,bj) = 0.0
592                   gvCD(i,j,k,bi,bj) = 0.0
593                 END DO
594               END DO
595    #endif   /* INCLUDE_CD_CODE */
596    #endif   /* ALLOW_AUTODIFF_TAMC */
597             ENDIF
598    
599    
600    C--     end of dynamics k loop (1:Nr)
601            ENDDO
602    
603    
604    
605    C--     Implicit viscosity
606            IF (implicitViscosity.AND.momStepping) THEN
607    #ifdef    ALLOW_AUTODIFF_TAMC
608              idkey = iikey + 3
609    #endif    /* ALLOW_AUTODIFF_TAMC */
610              CALL IMPLDIFF(
611         I         bi, bj, iMin, iMax, jMin, jMax,
612         I         deltaTmom, KappaRU,recip_HFacW,
613         U         gUNm1,
614         I         myThid )
615    #ifdef    ALLOW_AUTODIFF_TAMC
616              idkey = iikey + 4
617    #endif    /* ALLOW_AUTODIFF_TAMC */
618              CALL IMPLDIFF(
619         I         bi, bj, iMin, iMax, jMin, jMax,
620         I         deltaTmom, KappaRV,recip_HFacS,
621         U         gVNm1,
622         I         myThid )
623    
624    #ifdef    INCLUDE_CD_CODE
625    #ifdef    ALLOW_AUTODIFF_TAMC
626              idkey = iikey + 5
627    #endif    /* ALLOW_AUTODIFF_TAMC */
628              CALL IMPLDIFF(
629         I         bi, bj, iMin, iMax, jMin, jMax,
630         I         deltaTmom, KappaRU,recip_HFacW,
631         U         vVelD,
632         I         myThid )
633    #ifdef    ALLOW_AUTODIFF_TAMC
634              idkey = iikey + 6
635    #endif    /* ALLOW_AUTODIFF_TAMC */
636              CALL IMPLDIFF(
637         I         bi, bj, iMin, iMax, jMin, jMax,
638         I         deltaTmom, KappaRV,recip_HFacS,
639         U         uVelD,
640         I         myThid )
641    #endif    /* INCLUDE_CD_CODE */
642    C--     End If implicitViscosity.AND.momStepping
643          ENDIF          ENDIF
644    
645         ENDDO         ENDDO
646        ENDDO        ENDDO
647    
 C     write(0,*) 'dynamics: pS ',minval(cg2d_x(1:sNx,1:sNy,:,:)),  
 C    &                           maxval(cg2d_x(1:sNx,1:sNy,:,:))  
       write(0,*) 'dynamics: U  ',minval(uVel(1:sNx,1:sNy,1,:,:),mask=uVel(1:sNx,1:sNy,1,:,:).NE.0.),  
      &                           maxval(uVel(1:sNx,1:sNy,1,:,:))  
       write(0,*) 'dynamics: V  ',minval(vVel(1:sNx,1:sNy,1,:,:),mask=vVel(1:sNx,1:sNy,1,:,:).NE.0.),  
      &                           maxval(vVel(1:sNx,1:sNy,1,:,:))  
       write(0,*) 'dynamics: wVel(1) ',  
      &            minval(wVel(1:sNx,1:sNy,1),mask=wVel(1:sNx,1:sNy,1).NE.0.),  
      &            maxval(wVel(1:sNx,1:sNy,1))  
       write(0,*) 'dynamics: wVel(2) ',  
      &            minval(wVel(1:sNx,1:sNy,2),mask=wVel(1:sNx,1:sNy,2).NE.0.),  
      &            maxval(wVel(1:sNx,1:sNy,2))  
 cblk  write(0,*) 'dynamics: K13',minval(K13(1:sNx,1:sNy,:)),  
 cblk &                           maxval(K13(1:sNx,1:sNy,:))  
 cblk  write(0,*) 'dynamics: K23',minval(K23(1:sNx,1:sNy,:)),  
 cblk &                           maxval(K23(1:sNx,1:sNy,:))  
 cblk  write(0,*) 'dynamics: K33',minval(K33(1:sNx,1:sNy,:)),  
 cblk &                           maxval(K33(1:sNx,1:sNy,:))  
 C     write(0,*) 'dynamics: gT ',minval(gT(1:sNx,1:sNy,:,:,:)),  
 C    &                           maxval(gT(1:sNx,1:sNy,:,:,:))  
 C     write(0,*) 'dynamics: T  ',minval(Theta(1:sNx,1:sNy,:,:,:)),  
 C    &                           maxval(Theta(1:sNx,1:sNy,:,:,:))  
 C     write(0,*) 'dynamics: gS ',minval(gS(1:sNx,1:sNy,:,:,:)),  
 C    &                           maxval(gS(1:sNx,1:sNy,:,:,:))  
 C     write(0,*) 'dynamics: S  ',minval(salt(1:sNx,1:sNy,:,:,:)),  
 C    &                           maxval(salt(1:sNx,1:sNy,:,:,:))  
       write(0,*) 'dynamics: pH ',minval(pH/(Gravity*Rhonil),mask=ph.NE.0.),  
      &                           maxval(pH/(Gravity*Rhonil))  
   
648        RETURN        RETURN
649        END        END
650    
651    
652    C--      Cumulative diagnostic calculations (ie. time-averaging)
653    #ifdef INCLUDE_DIAGNOSTICS_INTERFACE_CODE
654    c        IF (taveFreq.GT.0.) THEN
655    c         CALL DO_TIME_AVERAGES(
656    c    I                           myTime, myIter, bi, bj, k, kup, kDown,
657    c    I                           ConvectCount,
658    c    I                           myThid )
659    c        ENDIF
660    #endif
661    

Legend:
Removed from v.1.19  
changed lines
  Added in v.1.54.2.3

  ViewVC Help
Powered by ViewVC 1.1.22