/[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.19 by adcroft, Wed May 26 20:26:41 1999 UTC revision 1.40 by jmc, Fri Apr 15 14:18:50 2005 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           K13,K23,KappaRS,KapGM,       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"  #include "PACKAGES_CONFIG.h"
52  #include "FFIELDS.h"  #ifdef ALLOW_GENERIC_ADVDIFF
53  #ifdef ALLOW_KPP  #include "GAD.h"
 #include "KPPMIX.h"  
54  #endif  #endif
55    
56    C     !INPUT/OUTPUT PARAMETERS:
57  C     == Routine arguments ==  C     == Routine arguments ==
58  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  
59  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.
60  C     maskUp  - Land mask used to denote base of the domain.  C     maskUp  :: Land mask used to denote base of the domain.
61  C     maskC   - Land mask for salt cells (used in TOP_LAYER only)  C     xA      :: Tracer cell face area normal to X
62  C     xA      - Tracer cell face area normal to X  C     yA      :: Tracer cell face area normal to X
63  C     yA      - Tracer cell face area normal to X  C     uTrans  :: Zonal volume transport through cell face
64  C     uTrans  - Zonal volume transport through cell face  C     vTrans  :: Meridional volume transport through cell face
65  C     vTrans  - Meridional volume transport through cell face  C     rTrans  ::   Vertical volume transport at interface k
66  C     rTrans  - Vertical volume transport through cell face  C     rTransKp1 :: Vertical volume transport at inteface k+1
67  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  
68  C                                      results will be set.  C                                      results will be set.
69  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)  
70        _RL fVerS (1-OLx:sNx+OLx,1-OLy:sNy+OLy,2)        _RL fVerS (1-OLx:sNx+OLx,1-OLy:sNy+OLy,2)
71        _RS xA    (1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RS xA    (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
72        _RS yA    (1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RS yA    (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
73        _RL uTrans(1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RL uTrans(1-OLx:sNx+OLx,1-OLy:sNy+OLy)
74        _RL vTrans(1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RL vTrans(1-OLx:sNx+OLx,1-OLy:sNy+OLy)
75        _RL rTrans(1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RL rTrans(1-OLx:sNx+OLx,1-OLy:sNy+OLy)
76          _RL rTransKp1(1-OLx:sNx+OLx,1-OLy:sNy+OLy)
77        _RS maskUp(1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RS maskUp(1-OLx:sNx+OLx,1-OLy:sNy+OLy)
78        _RS maskC (1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RL KappaRS(1-OLx:sNx+OLx,1-OLy:sNy+OLy)
       _RL K13   (1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr)  
       _RL K23   (1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr)  
       _RL KappaRS(1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr)  
       _RL KapGM (1-OLx:sNx+OLx,1-OLy:sNy+OLy)  
       _RL af    (1-OLx:sNx+OLx,1-OLy:sNy+OLy)  
       _RL df    (1-OLx:sNx+OLx,1-OLy:sNy+OLy)  
79        INTEGER k,kUp,kDown,kM1        INTEGER k,kUp,kDown,kM1
80        INTEGER bi,bj,iMin,iMax,jMin,jMax        INTEGER bi,bj,iMin,iMax,jMin,jMax
81        _RL     myCurrentTime        _RL     myTime
82          INTEGER myIter
83        INTEGER myThid        INTEGER myThid
 CEndOfInterface  
84    
85  C     == Local variables ==  CEOP
 C     I, J, K - Loop counters  
       INTEGER i,j  
       LOGICAL TOP_LAYER  
       _RL afFacS, dfFacS  
       _RL dSdx(1-OLx:sNx+OLx,1-OLy:sNy+OLy)  
       _RL dSdy(1-OLx:sNx+OLx,1-OLy:sNy+OLy)  
       _RL df4   (1-OLx:sNx+OLx,1-OLy:sNy+OLy)  
   
       afFacS = 1. _d 0  
       dfFacS = 1. _d 0  
       TOP_LAYER = K .EQ. 1  
   
 C---  Calculate advective and diffusive fluxes between cells.  
   
 #ifdef INCLUDE_T_DIFFUSION_CODE  
 C     o Zonal tracer gradient  
       DO j=1-Oly,sNy+Oly  
        DO i=1-Olx+1,sNx+Olx  
         dSdx(i,j) = _recip_dxC(i,j,bi,bj)*  
      &  (salt(i,j,k,bi,bj)-salt(i-1,j,k,bi,bj))  
        ENDDO  
       ENDDO  
 C     o Meridional tracer gradient  
       DO j=1-Oly+1,sNy+Oly  
        DO i=1-Olx,sNx+Olx  
         dSdy(i,j) = _recip_dyC(i,j,bi,bj)*  
      &  (salt(i,j,k,bi,bj)-salt(i,j-1,k,bi,bj))  
        ENDDO  
       ENDDO  
   
 C--   del^2 of S, needed for bi-harmonic (del^4) term  
       IF (diffK4S .NE. 0.) THEN  
        DO j=1-Oly+1,sNy+Oly-1  
         DO i=1-Olx+1,sNx+Olx-1  
          df4(i,j)= _recip_hFacC(i,j,k,bi,bj)  
      &             *recip_drF(k)/_rA(i,j,bi,bj)  
      &            *(  
      &             +( xA(i+1,j)*dSdx(i+1,j)-xA(i,j)*dSdx(i,j) )  
      &             +( yA(i,j+1)*dSdy(i,j+1)-yA(i,j)*dSdy(i,j) )  
      &             )  
         ENDDO  
        ENDDO  
       ENDIF  
 #endif  
86    
87  C--   Zonal flux (fZon is at west face of "salt" cell)  #ifdef ALLOW_GENERIC_ADVDIFF
88  C     Advective component of zonal flux  C     === Local variables ===
89        DO j=jMin,jMax        LOGICAL calcAdvection
90         DO i=iMin,iMax        INTEGER iterNb
91          af(i,j) =  
92       &   uTrans(i,j)*(salt(i,j,k,bi,bj)+salt(i-1,j,k,bi,bj))*0.5 _d 0  #ifdef ALLOW_AUTODIFF_TAMC
93         ENDDO  C--   only the kUp part of fverS is set in this subroutine
94        ENDDO  C--   the kDown is still required
95  C     o Diffusive component of zonal flux        fVerS(1,1,kDown) = fVerS(1,1,kDown)
96        DO j=jMin,jMax  #endif
        DO i=iMin,iMax  
         df(i,j) = -(diffKhS+0.5*(KapGM(i,j)+KapGM(i-1,j)))*  
      &            xA(i,j)*dSdx(i,j)  
        ENDDO  
       ENDDO  
 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+0.5*(KapGM(i,j)+KapGM(i,j-1)))*  
      &            yA(i,j)*dSdy(i,j)  
        ENDDO  
       ENDDO  
 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  
97    
98  C     Net meridional flux        calcAdvection = saltAdvection .AND. .NOT.saltMultiDimAdvec
99        DO j=jMin,jMax        CALL GAD_CALC_RHS(
100         DO i=iMin,iMax       I           bi,bj,iMin,iMax,jMin,jMax,k,kM1,kUp,kDown,
101          fMer(i,j) = afFacS*af(i,j) + dfFacS*df(i,j)       I           xA,yA,uTrans,vTrans,rTrans,rTransKp1,maskUp,
102         ENDDO       I           uVel, vVel, wVel,
103        ENDDO       I           diffKhS, diffK4S, KappaRS, Salt,
104         I           GAD_SALINITY, saltAdvScheme, saltVertAdvScheme,
105  C--   Interpolate terms for Redi/GM scheme       I           calcAdvection, saltImplVertAdv,
106        DO j=jMin,jMax       U           fVerS, gS,
107         DO i=iMin,iMax       I           myTime, myIter, myThid )
108          dSdx(i,j) = 0.5*(  
109       &   +0.5*(_maskW(i+1,j,k,bi,bj)  C--   External salinity forcing term(s) inside Adams-Bashforth:
110       &         *_recip_dxC(i+1,j,bi,bj)*        IF ( saltForcing .AND. forcing_In_AB )
111       &           (salt(i+1,j,k,bi,bj)-salt(i,j,k,bi,bj))       & CALL EXTERNAL_FORCING_S(
112       &        +_maskW(i,j,k,bi,bj)       I     iMin,iMax,jMin,jMax,bi,bj,k,
113       &         *_recip_dxC(i,j,bi,bj)*       I     myTime,myThid)
      &           (salt(i,j,k,bi,bj)-salt(i-1,j,k,bi,bj)))  
      &   +0.5*(_maskW(i+1,j,km1,bi,bj)  
      &         *_recip_dxC(i+1,j,bi,bj)*  
      &           (salt(i+1,j,km1,bi,bj)-salt(i,j,km1,bi,bj))  
      &        +_maskW(i,j,km1,bi,bj)  
      &         *_recip_dxC(i,j,bi,bj)*  
      &           (salt(i,j,km1,bi,bj)-salt(i-1,j,km1,bi,bj)))  
      &       )  
        ENDDO  
       ENDDO  
       DO j=jMin,jMax  
        DO i=iMin,iMax  
         dSdy(i,j) = 0.5*(  
      &   +0.5*(_maskS(i,j,k,bi,bj)  
      &         *_recip_dyC(i,j,bi,bj)*  
      &           (salt(i,j,k,bi,bj)-salt(i,j-1,k,bi,bj))  
      &        +_maskS(i,j+1,k,bi,bj)  
      &         *_recip_dyC(i,j+1,bi,bj)*  
      &           (salt(i,j+1,k,bi,bj)-salt(i,j,k,bi,bj)))  
      &   +0.5*(_maskS(i,j,km1,bi,bj)  
      &         *_recip_dyC(i,j,bi,bj)*  
      &           (salt(i,j,km1,bi,bj)-salt(i,j-1,km1,bi,bj))  
      &        +_maskS(i,j+1,km1,bi,bj)  
      &         *_recip_dyC(i,j+1,bi,bj)*  
      &           (salt(i,j+1,km1,bi,bj)-salt(i,j,km1,bi,bj)))  
      &       )  
        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     Diffusive component of vertical flux  
 C     Note: For K=1 then KM1=1 this gives a dS/dz = 0 upper  
 C           boundary condition.  
       DO j=jMin,jMax  
        DO i=iMin,iMax  
         df(i,j) = _rA(i,j,bi,bj)*(  
      &   -KapGM(i,j)*K13(i,j,k)*dSdx(i,j)  
      &   -KapGM(i,j)*K23(i,j,k)*dSdy(i,j)  
      &   )  
        ENDDO  
       ENDDO  
       IF (.NOT.implicitDiffusion) THEN  
        DO j=jMin,jMax  
         DO i=iMin,iMax  
          df(i,j) = 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  
       ENDIF  
 #ifdef ALLOW_KPP  
       IF (usingKPPmixing) THEN  
 C--   Add non local transport coefficient (ghat term) to right-hand-side  
 C     The nonlocal transport term is noNrero only for scalars in unstable  
 C     (convective) forcing conditions.  
        IF ( TOP_LAYER ) THEN  
         DO j=jMin,jMax  
          DO i=iMin,iMax  
           df(i,j) = df(i,j) - _rA(i,j,bi,bj) *  
      &              EmPmR(i,j,bi,bj) * delZ(1) *  
      &              ( KappaRS(i,j,k)   * KPPghat(i,j,k,bi,bj)   )  
          ENDDO  
         ENDDO  
        ELSE  
         DO j=jMin,jMax  
          DO i=iMin,iMax  
           df(i,j) = df(i,j) - _rA(i,j,bi,bj) *  
      &              EmPmR(i,j,bi,bj) * delZ(1) *  
      &              ( KappaRS(i,j,k)   * KPPghat(i,j,k,bi,bj)  
      &              - KappaRS(i,j,k-1) * KPPghat(i,j,k-1,bi,bj) )  
          ENDDO  
         ENDDO  
        ENDIF  
       ENDIF  
 #endif /* ALLOW_KPP */  
114    
115  C     Net vertical flux        IF ( saltAdamsBashforth ) THEN
116        DO j=jMin,jMax          iterNb = myIter
117         DO i=iMin,iMax          IF (staggerTimeStep) iterNb = myIter - 1
118          fVerS(i,j,kUp) = ( afFacS*af(i,j)+  dfFacS*df(i,j) )*maskUp(i,j)  #ifdef ALLOW_ADAMSBASHFORTH_3
119         ENDDO          CALL ADAMS_BASHFORTH3(
120        ENDDO       I                        bi, bj, k,
121        IF ( TOP_LAYER ) THEN       U                        gS, gsNm,
122         DO j=jMin,jMax       I                        iterNb, myThid )
123          DO i=iMin,iMax  #else
124           fVerS(i,j,kUp) = afFacS*af(i,j)*freeSurfFac          CALL ADAMS_BASHFORTH2(
125          ENDDO       I                        bi, bj, k,
126         ENDDO       U                        gS, gsNm1,
127         I                        iterNb, myThid )
128    #endif
129        ENDIF        ENDIF
130    
131  C--   Tendency is minus divergence of the fluxes.  C--   External salinity forcing term(s) outside Adams-Bashforth:
132  C     Note. Tendency terms will only be correct for range        IF ( saltForcing .AND. .NOT.forcing_In_AB )
133  C           i=iMin+1:iMax-1, j=jMin+1:jMax-1. Edge points       & CALL EXTERNAL_FORCING_S(
 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(  
134       I     iMin,iMax,jMin,jMax,bi,bj,k,       I     iMin,iMax,jMin,jMax,bi,bj,k,
135       I     maskC,       I     myTime,myThid)
      I     myCurrentTime,myThid)  
136    
137  #ifdef INCLUDE_LAT_CIRC_FFT_FILTER_CODE  #ifdef NONLIN_FRSURF
138  C--        IF (nonlinFreeSurf.GT.0) THEN
139        CALL FILTER_LATCIRCS_FFT_APPLY( gS, 1, sNy, k, k, bi, bj, 1, myThid)          CALL FREESURF_RESCALE_G(
140         I                          bi, bj, k,
141         U                          gS,
142         I                          myThid )
143            IF ( saltAdamsBashforth ) THEN
144    #ifdef ALLOW_ADAMSBASHFORTH_3
145            CALL FREESURF_RESCALE_G(
146         I                          bi, bj, k,
147         U                          gsNm(1-OLx,1-OLy,1,1,1,1),
148         I                          myThid )
149            CALL FREESURF_RESCALE_G(
150         I                          bi, bj, k,
151         U                          gsNm(1-OLx,1-OLy,1,1,1,2),
152         I                          myThid )
153    #else
154            CALL FREESURF_RESCALE_G(
155         I                          bi, bj, k,
156         U                          gsNm1,
157         I                          myThid )
158  #endif  #endif
159            ENDIF
160          ENDIF
161    #endif /* NONLIN_FRSURF */
162    
163    #endif /* ALLOW_GENERIC_ADVDIFF */
164    
165        RETURN        RETURN
166        END        END

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

  ViewVC Help
Powered by ViewVC 1.1.22