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

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

  ViewVC Help
Powered by ViewVC 1.1.22