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

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

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

revision 1.21 by adcroft, Wed Jun 21 19:15:26 2000 UTC revision 1.46 by jmc, Tue Mar 7 15:28:02 2006 UTC
# Line 1  Line 1 
1  C $Header$  C $Header$
2    C $Name$
3    
4    #include "PACKAGES_CONFIG.h"
5  #include "CPP_OPTIONS.h"  #include "CPP_OPTIONS.h"
6    
7  CStartOfInterFace  CBOP
8    C     !ROUTINE: CALC_GS
9    C     !INTERFACE:
10        SUBROUTINE CALC_GS(        SUBROUTINE CALC_GS(
11       I           bi,bj,iMin,iMax,jMin,jMax,k,kM1,kUp,kDown,       I           bi,bj,iMin,iMax,jMin,jMax,k,kM1,kUp,kDown,
12       I           xA,yA,uTrans,vTrans,rTrans,maskup,maskC,       I           xA,yA,uTrans,vTrans,rTrans,rTransKp1,maskUp,
13       I           KappaRS,       I           KappaRS,
14       U           af,df,fZon,fMer,fVerS,       U           fVerS,
15       I           myCurrentTime, myThid )       I           myTime,myIter,myThid )
16  C     /==========================================================\  C     !DESCRIPTION: \bv
17  C     | SUBROUTINE CALC_GS                                       |  C     *==========================================================*
18  C     | o Calculate the salt tendency terms.                     |  C     | SUBROUTINE CALC_GS                                        
19  C     |==========================================================|  C     | o Calculate the salt tendency terms.                      
20  C     | A procedure called EXTERNAL_FORCING_S is called from     |  C     *==========================================================*
21  C     | here. These procedures can be used to add per problem    |  C     | A procedure called EXTERNAL_FORCING_S is called from      
22  C     | E-P  flux source terms.                                  |  C     | here. These procedures can be used to add per problem    
23  C     | Note: Although it is slightly counter-intuitive the      |  C     | E-P  flux source terms.                                  
24  C     |       EXTERNAL_FORCING routine is not the place to put   |  C     | Note: Although it is slightly counter-intuitive the      
25  C     |       file I/O. Instead files that are required to       |  C     |       EXTERNAL_FORCING routine is not the place to put    
26  C     |       calculate the external source terms are generally  |  C     |       file I/O. Instead files that are required to        
27  C     |       read during the model main loop. This makes the    |  C     |       calculate the external source terms are generally  
28  C     |       logisitics of multi-processing simpler and also    |  C     |       read during the model main loop. This makes the    
29  C     |       makes the adjoint generation simpler. It also      |  C     |       logisitics of multi-processing simpler and also    
30  C     |       allows for I/O to overlap computation where that   |  C     |       makes the adjoint generation simpler. It also      
31  C     |       is supported by hardware.                          |  C     |       allows for I/O to overlap computation where that    
32  C     | Aside from the problem specific term the code here       |  C     |       is supported by hardware.                          
33  C     | forms the tendency terms due to advection and mixing     |  C     | Aside from the problem specific term the code here        
34  C     | The baseline implementation here uses a centered         |  C     | forms the tendency terms due to advection and mixing      
35  C     | difference form for the advection term and a tensorial   |  C     | The baseline implementation here uses a centered          
36  C     | divergence of a flux form for the diffusive term. The    |  C     | difference form for the advection term and a tensorial    
37  C     | diffusive term is formulated so that isopycnal mixing and|  C     | divergence of a flux form for the diffusive term. The    
38  C     | GM-style subgrid-scale terms can be incorporated b simply|  C     | diffusive term is formulated so that isopycnal mixing and
39  C     | setting the diffusion tensor terms appropriately.        |  C     | GM-style subgrid-scale terms can be incorporated b simply
40  C     \==========================================================/  C     | setting the diffusion tensor terms appropriately.        
41        IMPLICIT NONE  C     *==========================================================*
42    C     \ev
43    
44    C     !USES:
45          IMPLICIT NONE
46  C     == GLobal variables ==  C     == GLobal variables ==
47  #include "SIZE.h"  #include "SIZE.h"
48  #include "DYNVARS.h"  #include "DYNVARS.h"
49  #include "EEPARAMS.h"  #include "EEPARAMS.h"
50  #include "PARAMS.h"  #include "PARAMS.h"
51  #include "GRID.h"  #ifdef ALLOW_GENERIC_ADVDIFF
52  #include "FFIELDS.h"  #include "GAD.h"
53    #endif
54    #ifdef ALLOW_AUTODIFF_TAMC
55    # include "tamc.h"
56    # include "tamc_keys.h"
57    #endif
58    
59    C     !INPUT/OUTPUT PARAMETERS:
60  C     == Routine arguments ==  C     == Routine arguments ==
61  C     fZon    - Work array for flux of temperature in the east-west  C     fVerS   :: Flux of salt (S) in the vertical
 C               direction at the west face of a cell.  
 C     fMer    - Work array for flux of temperature in the north-south  
 C               direction at the south face of a cell.  
 C     fVerS   - Flux of salt (S) in the vertical  
62  C               direction at the upper(U) and lower(D) faces of a cell.  C               direction at the upper(U) and lower(D) faces of a cell.
63  C     maskUp  - Land mask used to denote base of the domain.  C     maskUp  :: Land mask used to denote base of the domain.
64  C     maskC   - Land mask for salt cells (used in TOP_LAYER only)  C     xA      :: Tracer cell face area normal to X
65  C     xA      - Tracer cell face area normal to X  C     yA      :: Tracer cell face area normal to X
66  C     yA      - Tracer cell face area normal to X  C     uTrans  :: Zonal volume transport through cell face
67  C     uTrans  - Zonal volume transport through cell face  C     vTrans  :: Meridional volume transport through cell face
68  C     vTrans  - Meridional volume transport through cell face  C     rTrans  ::   Vertical volume transport at interface k
69  C     rTrans  - Vertical volume transport through cell face  C     rTransKp1 :: Vertical volume transport at inteface k+1
70  C     af      - Advective flux component work array  C     bi, bj, iMin, iMax, jMin, jMax :: Range of points for which calculation
 C     df      - Diffusive flux component work array  
 C     bi, bj, iMin, iMax, jMin, jMax - Range of points for which calculation  
71  C                                      results will be set.  C                                      results will be set.
72  C     myThid - Instance number for this innvocation of CALC_GT  C     myThid :: Instance number for this innvocation of CALC_GT
       _RL fZon  (1-OLx:sNx+OLx,1-OLy:sNy+OLy)  
       _RL fMer  (1-OLx:sNx+OLx,1-OLy:sNy+OLy)  
73        _RL fVerS (1-OLx:sNx+OLx,1-OLy:sNy+OLy,2)        _RL fVerS (1-OLx:sNx+OLx,1-OLy:sNy+OLy,2)
74        _RS xA    (1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RS xA    (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
75        _RS yA    (1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RS yA    (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
76        _RL uTrans(1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RL uTrans(1-OLx:sNx+OLx,1-OLy:sNy+OLy)
77        _RL vTrans(1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RL vTrans(1-OLx:sNx+OLx,1-OLy:sNy+OLy)
78        _RL rTrans(1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RL rTrans(1-OLx:sNx+OLx,1-OLy:sNy+OLy)
79          _RL rTransKp1(1-OLx:sNx+OLx,1-OLy:sNy+OLy)
80        _RS maskUp(1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RS maskUp(1-OLx:sNx+OLx,1-OLy:sNy+OLy)
81        _RS maskC (1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RL KappaRS(1-OLx:sNx+OLx,1-OLy:sNy+OLy)
       _RL KappaRS(1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr)  
       _RL af    (1-OLx:sNx+OLx,1-OLy:sNy+OLy)  
       _RL df    (1-OLx:sNx+OLx,1-OLy:sNy+OLy)  
82        INTEGER k,kUp,kDown,kM1        INTEGER k,kUp,kDown,kM1
83        INTEGER bi,bj,iMin,iMax,jMin,jMax        INTEGER bi,bj,iMin,iMax,jMin,jMax
84        _RL     myCurrentTime        _RL     myTime
85          INTEGER myIter
86        INTEGER myThid        INTEGER myThid
 CEndOfInterface  
87    
88  C     == Local variables ==  CEOP
89  C     I, J, K - Loop counters  
90        INTEGER i,j  #ifdef ALLOW_GENERIC_ADVDIFF
91        LOGICAL TOP_LAYER  C     === Local variables ===
92        _RL afFacS, dfFacS        LOGICAL calcAdvection
93        _RL dSdx(1-OLx:sNx+OLx,1-OLy:sNy+OLy)        INTEGER iterNb
94        _RL dSdy(1-OLx:sNx+OLx,1-OLy:sNy+OLy)  #ifdef ALLOW_ADAMSBASHFORTH_3
95        _RL df4   (1-OLx:sNx+OLx,1-OLy:sNy+OLy)        INTEGER m1, m2
96    #endif
97    
98    #ifdef ALLOW_AUTODIFF_TAMC
99              act1 = bi - myBxLo(myThid)
100              max1 = myBxHi(myThid) - myBxLo(myThid) + 1
101              act2 = bj - myByLo(myThid)
102              max2 = myByHi(myThid) - myByLo(myThid) + 1
103              act3 = myThid - 1
104              max3 = nTx*nTy
105              act4 = ikey_dynamics - 1
106              itdkey = (act1 + 1) + act2*max1
107         &                      + act3*max1*max2
108         &                      + act4*max1*max2*max3
109              kkey = (itdkey-1)*Nr + k
110    #endif /* ALLOW_AUTODIFF_TAMC */
111    
112  #ifdef ALLOW_AUTODIFF_TAMC  #ifdef ALLOW_AUTODIFF_TAMC
113  C--   only the kUp part of fverS is set in this subroutine  C--   only the kUp part of fverS is set in this subroutine
114  C--   the kDown is still required  C--   the kDown is still required
   
115        fVerS(1,1,kDown) = fVerS(1,1,kDown)        fVerS(1,1,kDown) = fVerS(1,1,kDown)
116        DO j=1-OLy,sNy+OLy  # ifdef NONLIN_FRSURF
117         DO i=1-OLx,sNx+OLx  CADJ STORE fVerS(:,:,:) =
118          fZon(i,j)      = 0.0  CADJ &     comlev1_bibj_k, key=kkey, byte=isbyte
119          fMer(i,j)      = 0.0  CADJ STORE gsNm1(:,:,k,bi,bj) =
120          fVerS(i,j,kUp) = 0.0  CADJ &     comlev1_bibj_k, key=kkey, byte=isbyte
121         ENDDO  # endif
122        ENDDO  #endif
123  #endif  
124    C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
125        afFacS = 1. _d 0  
126        dfFacS = 1. _d 0        calcAdvection = saltAdvection .AND. .NOT.saltMultiDimAdvec
127        TOP_LAYER = K .EQ. 1        iterNb = myIter
128          IF (staggerTimeStep) iterNb = myIter - 1
129  C---  Calculate advective and diffusive fluxes between cells.  
130    #ifdef ALLOW_ADAMSBASHFORTH_3
131  #ifdef INCLUDE_T_DIFFUSION_CODE          m1 = 1 + MOD(iterNb+1,2)
132  C     o Zonal tracer gradient          m2 = 1 + MOD( iterNb ,2)
133        DO j=1-Oly,sNy+Oly          CALL GAD_CALC_RHS(
134         DO i=1-Olx+1,sNx+Olx       I           bi,bj,iMin,iMax,jMin,jMax,k,kM1,kUp,kDown,
135          dSdx(i,j) = _recip_dxC(i,j,bi,bj)*       I           xA,yA,uTrans,vTrans,rTrans,rTransKp1,maskUp,
136       &  (salt(i,j,k,bi,bj)-salt(i-1,j,k,bi,bj))       I           uVel, vVel, wVel,
137         ENDDO       I           diffKhS, diffK4S, KappaRS,
138        ENDDO       I           gsNm(1-Olx,1-Oly,1,1,1,m2), salt,
139  C     o Meridional tracer gradient       I           GAD_SALINITY, saltAdvScheme, saltVertAdvScheme,
140        DO j=1-Oly+1,sNy+Oly       I           calcAdvection, saltImplVertAdv, AdamsBashforth_S,
141         DO i=1-Olx,sNx+Olx       U           fVerS, gS,
142          dSdy(i,j) = _recip_dyC(i,j,bi,bj)*       I           myTime, myIter, myThid )
143       &  (salt(i,j,k,bi,bj)-salt(i,j-1,k,bi,bj))  #else /* ALLOW_ADAMSBASHFORTH_3 */
144         ENDDO          CALL GAD_CALC_RHS(
145        ENDDO       I           bi,bj,iMin,iMax,jMin,jMax,k,kM1,kUp,kDown,
146         I           xA,yA,uTrans,vTrans,rTrans,rTransKp1,maskUp,
147  C--   del^2 of S, needed for bi-harmonic (del^4) term       I           uVel, vVel, wVel,
148        IF (diffK4S .NE. 0.) THEN       I           diffKhS, diffK4S, KappaRS, gsNm1, salt,
149         DO j=1-Oly+1,sNy+Oly-1       I           GAD_SALINITY, saltAdvScheme, saltVertAdvScheme,
150          DO i=1-Olx+1,sNx+Olx-1       I           calcAdvection, saltImplVertAdv, AdamsBashforth_S,
151           df4(i,j)= _recip_hFacC(i,j,k,bi,bj)       U           fVerS, gS,
152       &             *recip_drF(k)/_rA(i,j,bi,bj)       I           myTime, myIter, myThid )
153       &            *(  #endif /* ALLOW_ADAMSBASHFORTH_3 */
154       &             +( xA(i+1,j)*dSdx(i+1,j)-xA(i,j)*dSdx(i,j) )  
155       &             +( yA(i,j+1)*dSdy(i,j+1)-yA(i,j)*dSdy(i,j) )  C--   External salinity forcing term(s) inside Adams-Bashforth:
156       &             )        IF ( saltForcing .AND. tracForcingOutAB.NE.1 )
157          ENDDO       & CALL EXTERNAL_FORCING_S(
158         ENDDO       I     iMin,iMax,jMin,jMax,bi,bj,k,
159        ENDIF       I     myTime,myThid)
 #endif  
160    
161  C--   Zonal flux (fZon is at west face of "salt" cell)        IF ( AdamsBashforthGs ) THEN
162  C     Advective component of zonal flux  #ifdef ALLOW_ADAMSBASHFORTH_3
163        DO j=jMin,jMax          CALL ADAMS_BASHFORTH3(
164         DO i=iMin,iMax       I                        bi, bj, k,
165          af(i,j) =       U                        gS, gsNm,
166       &   uTrans(i,j)*(salt(i,j,k,bi,bj)+salt(i-1,j,k,bi,bj))*0.5 _d 0       I                        saltStartAB, iterNb, myThid )
167         ENDDO  #else
168        ENDDO          CALL ADAMS_BASHFORTH2(
169  C     o Diffusive component of zonal flux       I                        bi, bj, k,
170        DO j=jMin,jMax       U                        gS, gsNm1,
171         DO i=iMin,iMax       I                        iterNb, myThid )
         df(i,j) = -diffKhS*xA(i,j)*dSdx(i,j)  
        ENDDO  
       ENDDO  
 #ifdef ALLOW_GMREDI  
       IF (use_GMRedi) CALL GMREDI_XTRANSPORT(  
      I     iMin,iMax,jMin,jMax,bi,bj,K,  
      I     xA,salt,  
      U     df,  
      I     myThid)  
172  #endif  #endif
 C     o Add the bi-harmonic contribution  
       IF (diffK4S .NE. 0.) THEN  
        DO j=jMin,jMax  
         DO i=iMin,iMax  
          df(i,j) = df(i,j) + xA(i,j)*  
      &    diffK4S*(df4(i,j)-df4(i-1,j))*_recip_dxC(i,j,bi,bj)  
         ENDDO  
        ENDDO  
       ENDIF  
 C     Net zonal flux  
       DO j=jMin,jMax  
        DO i=iMin,iMax  
         fZon(i,j) = afFacS*af(i,j) + dfFacS*df(i,j)  
        ENDDO  
       ENDDO  
   
 C--   Meridional flux (fMer is at south face of "salt" cell)  
 C     Advective component of meridional flux  
       DO j=jMin,jMax  
        DO i=iMin,iMax  
 C       Advective component of meridional flux  
         af(i,j) =  
      &   vTrans(i,j)*(salt(i,j,k,bi,bj)+salt(i,j-1,k,bi,bj))*0.5 _d 0  
        ENDDO  
       ENDDO  
 C     Diffusive component of meridional flux  
       DO j=jMin,jMax  
        DO i=iMin,iMax  
         df(i,j) = -diffKhS*yA(i,j)*dSdy(i,j)  
        ENDDO  
       ENDDO  
 #ifdef ALLOW_GMREDI  
       IF (use_GMRedi) CALL GMREDI_YTRANSPORT(  
      I     iMin,iMax,jMin,jMax,bi,bj,K,  
      I     yA,salt,  
      U     df,  
      I     myThid)  
 #endif  
 C     o Add the bi-harmonic contribution  
       IF (diffK4S .NE. 0.) THEN  
        DO j=jMin,jMax  
         DO i=iMin,iMax  
          df(i,j) = df(i,j) + yA(i,j)*  
      &    diffK4S*(df4(i,j)-df4(i,j-1))*_recip_dyC(i,j,bi,bj)  
         ENDDO  
        ENDDO  
       ENDIF  
   
 C     Net meridional flux  
       DO j=jMin,jMax  
        DO i=iMin,iMax  
         fMer(i,j) = afFacS*af(i,j) + dfFacS*df(i,j)  
        ENDDO  
       ENDDO  
   
 C--   Vertical flux (fVerS) above  
 C     Advective component of vertical flux  
 C     Note: For K=1 then KM1=1 this gives a barZ(T) = T  
 C     (this plays the role of the free-surface correction)  
       DO j=jMin,jMax  
        DO i=iMin,iMax  
         af(i,j) =  
      &   rTrans(i,j)*(salt(i,j,k,bi,bj)+salt(i,j,kM1,bi,bj))*0.5 _d 0  
        ENDDO  
       ENDDO  
 C     o Diffusive component of vertical flux  
 C     Note: For K=1 then KM1=1 and this gives a dS/dr = 0 upper  
 C           boundary condition.  
       IF (implicitDiffusion) THEN  
        DO j=jMin,jMax  
         DO i=iMin,iMax  
          df(i,j) = 0.  
         ENDDO  
        ENDDO  
       ELSE  
        DO j=jMin,jMax  
         DO i=iMin,iMax  
          df(i,j) = - _rA(i,j,bi,bj)*(  
      &    KappaRS(i,j,k)*recip_drC(k)  
      &    *(salt(i,j,kM1,bi,bj)-salt(i,j,k,bi,bj))*rkFac  
      &    )  
         ENDDO  
        ENDDO  
173        ENDIF        ENDIF
174    
175  #ifdef ALLOW_GMREDI  C--   External salinity forcing term(s) outside Adams-Bashforth:
176        IF (use_GMRedi) CALL GMREDI_RTRANSPORT(        IF ( saltForcing .AND. tracForcingOutAB.EQ.1 )
177       I     iMin,iMax,jMin,jMax,bi,bj,K,       & CALL EXTERNAL_FORCING_S(
178       I     maskUp,salt,       I     iMin,iMax,jMin,jMax,bi,bj,k,
179       U     df,       I     myTime,myThid)
      I     myThid)  
 #endif  
180    
181  #ifdef ALLOW_KPP  #ifdef NONLIN_FRSURF
182  C--   Add non-local KPP transport term (ghat) to diffusive salt flux.        IF (nonlinFreeSurf.GT.0) THEN
183        IF (use_KPPmixing) CALL KPP_TRANSPORT_S(          CALL FREESURF_RESCALE_G(
184       I     iMin,iMax,jMin,jMax,bi,bj,k,km1,       I                          bi, bj, k,
185       I     maskC,KappaRS,       U                          gS,
186       U     df )       I                          myThid )
187            IF ( AdamsBashforthGs ) THEN
188    #ifdef ALLOW_ADAMSBASHFORTH_3
189            CALL FREESURF_RESCALE_G(
190         I                          bi, bj, k,
191         U                          gsNm(1-OLx,1-OLy,1,1,1,1),
192         I                          myThid )
193            CALL FREESURF_RESCALE_G(
194         I                          bi, bj, k,
195         U                          gsNm(1-OLx,1-OLy,1,1,1,2),
196         I                          myThid )
197    #else
198            CALL FREESURF_RESCALE_G(
199         I                          bi, bj, k,
200         U                          gsNm1,
201         I                          myThid )
202  #endif  #endif
203            ENDIF
 C     Net vertical flux  
       DO j=jMin,jMax  
        DO i=iMin,iMax  
         fVerS(i,j,kUp) = ( afFacS*af(i,j)+  dfFacS*df(i,j) )*maskUp(i,j)  
        ENDDO  
       ENDDO  
       IF ( TOP_LAYER ) THEN  
        DO j=jMin,jMax  
         DO i=iMin,iMax  
          fVerS(i,j,kUp) = afFacS*af(i,j)*freeSurfFac  
         ENDDO  
        ENDDO  
204        ENDIF        ENDIF
205    #endif /* NONLIN_FRSURF */
206    
207  C--   Tendency is minus divergence of the fluxes.  #endif /* ALLOW_GENERIC_ADVDIFF */
 C     Note. Tendency terms will only be correct for range  
 C           i=iMin+1:iMax-1, j=jMin+1:jMax-1. Edge points  
 C           will contain valid floating point numbers but  
 C           they are not algorithmically correct. These points  
 C           are not used.  
       DO j=jMin,jMax  
        DO i=iMin,iMax  
 #define _recip_VolS1(i,j,k,bi,bj) _recip_hFacC(i,j,k,bi,bj)*recip_drF(k)  
 #define _recip_VolS2(i,j,k,bi,bj) /_rA(i,j,bi,bj)  
         gS(i,j,k,bi,bj)=  
      &   -_recip_VolS1(i,j,k,bi,bj)  
      &    _recip_VolS2(i,j,k,bi,bj)  
      &   *(  
      &    +( fZon(i+1,j)-fZon(i,j) )  
      &    +( fMer(i,j+1)-fMer(i,j) )  
      &    +( fVerS(i,j,kUp)-fVerS(i,j,kDown) )*rkFac  
      &    )  
        ENDDO  
       ENDDO  
   
 C--   External forcing term(s)  
       CALL EXTERNAL_FORCING_S(  
      I     iMin,iMax,jMin,jMax,bi,bj,k,  
      I     maskC,  
      I     myCurrentTime,myThid)  
   
 #ifdef INCLUDE_LAT_CIRC_FFT_FILTER_CODE  
 C--  
       CALL FILTER_LATCIRCS_FFT_APPLY( gS, 1, sNy, k, k, bi, bj, 1, myThid)  
 #endif  
208    
209        RETURN        RETURN
210        END        END

Legend:
Removed from v.1.21  
changed lines
  Added in v.1.46

  ViewVC Help
Powered by ViewVC 1.1.22