/[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.25 by cnh, Tue Feb 6 04:47:51 2001 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$  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           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    #include "GAD.h"
54    #endif
55    
56    C     !INPUT/OUTPUT PARAMETERS:
57  C     == Routine arguments ==  C     == Routine arguments ==
58  C     fVerS   - Flux of salt (S) in the vertical  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     bi, bj, iMin, iMax, jMin, jMax - Range of points for which calculation  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
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 KappaRS(1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr)  
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
86  C     I, J, K - Loop counters  
87        INTEGER i,j  #ifdef ALLOW_GENERIC_ADVDIFF
88        LOGICAL TOP_LAYER  C     === Local variables ===
89        _RL afFacS, dfFacS        LOGICAL calcAdvection
90        _RL dSdx(1-OLx:sNx+OLx,1-OLy:sNy+OLy)        INTEGER iterNb
       _RL dSdy(1-OLx:sNx+OLx,1-OLy:sNy+OLy)  
       _RL df4   (1-OLx:sNx+OLx,1-OLy:sNy+OLy)  
       _RL fZon  (1-OLx:sNx+OLx,1-OLy:sNy+OLy)  
       _RL fMer  (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)  
91    
92  #ifdef ALLOW_AUTODIFF_TAMC  #ifdef ALLOW_AUTODIFF_TAMC
93  C--   only the kUp part of fverS is set in this subroutine  C--   only the kUp part of fverS is set in this subroutine
94  C--   the kDown is still required  C--   the kDown is still required
   
95        fVerS(1,1,kDown) = fVerS(1,1,kDown)        fVerS(1,1,kDown) = fVerS(1,1,kDown)
       DO j=1-OLy,sNy+OLy  
        DO i=1-OLx,sNx+OLx  
         fZon(i,j)      = 0.0  
         fMer(i,j)      = 0.0  
         fVerS(i,j,kUp) = 0.0  
        ENDDO  
       ENDDO  
96  #endif  #endif
97    
98        afFacS = 1. _d 0        calcAdvection = saltAdvection .AND. .NOT.saltMultiDimAdvec
99        dfFacS = 1. _d 0        CALL GAD_CALC_RHS(
100        TOP_LAYER = K .EQ. 1       I           bi,bj,iMin,iMax,jMin,jMax,k,kM1,kUp,kDown,
101         I           xA,yA,uTrans,vTrans,rTrans,rTransKp1,maskUp,
102  C---  Calculate advective and diffusive fluxes between cells.       I           uVel, vVel, wVel,
103         I           diffKhS, diffK4S, KappaRS, Salt,
104  #ifdef INCLUDE_T_DIFFUSION_CODE       I           GAD_SALINITY, saltAdvScheme, saltVertAdvScheme,
105  C     o Zonal tracer gradient       I           calcAdvection, saltImplVertAdv,
106        DO j=1-Oly,sNy+Oly       U           fVerS, gS,
107         DO i=1-Olx+1,sNx+Olx       I           myTime, myIter, myThid )
108          dSdx(i,j) = _recip_dxC(i,j,bi,bj)*  
109       &  (salt(i,j,k,bi,bj)-salt(i-1,j,k,bi,bj))  C--   External salinity forcing term(s) inside Adams-Bashforth:
110         ENDDO        IF ( saltForcing .AND. forcing_In_AB )
111        ENDDO       & CALL EXTERNAL_FORCING_S(
112  C     o Meridional tracer gradient       I     iMin,iMax,jMin,jMax,bi,bj,k,
113        DO j=1-Oly+1,sNy+Oly       I     myTime,myThid)
        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  
114    
115  C--   Zonal flux (fZon is at west face of "salt" cell)        IF ( saltAdamsBashforth ) THEN
116  C     Advective component of zonal flux          iterNb = myIter
117        DO j=jMin,jMax          IF (staggerTimeStep) iterNb = myIter - 1
118         DO i=iMin,iMax  #ifdef ALLOW_ADAMSBASHFORTH_3
119          af(i,j) =          CALL ADAMS_BASHFORTH3(
120       &   uTrans(i,j)*(salt(i,j,k,bi,bj)+salt(i-1,j,k,bi,bj))*0.5 _d 0       I                        bi, bj, k,
121         ENDDO       U                        gS, gsNm,
122        ENDDO       I                        iterNb, myThid )
123  C     o Diffusive component of zonal flux  #else
124        DO j=jMin,jMax          CALL ADAMS_BASHFORTH2(
125         DO i=iMin,iMax       I                        bi, bj, k,
126          df(i,j) = -diffKhS*xA(i,j)*dSdx(i,j)       U                        gS, gsNm1,
127         ENDDO       I                        iterNb, myThid )
       ENDDO  
 #ifdef ALLOW_GMREDI  
       IF (useGMRedi) CALL GMREDI_XTRANSPORT(  
      I     iMin,iMax,jMin,jMax,bi,bj,K,  
      I     xA,salt,  
      U     df,  
      I     myThid)  
128  #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 (useGMRedi) 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  
129        ENDIF        ENDIF
130    
131  C     Net meridional flux  C--   External salinity forcing term(s) outside Adams-Bashforth:
132        DO j=jMin,jMax        IF ( saltForcing .AND. .NOT.forcing_In_AB )
133         DO i=iMin,iMax       & CALL EXTERNAL_FORCING_S(
134          fMer(i,j) = afFacS*af(i,j) + dfFacS*df(i,j)       I     iMin,iMax,jMin,jMax,bi,bj,k,
135         ENDDO       I     myTime,myThid)
       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  
       ENDIF  
   
 #ifdef ALLOW_GMREDI  
       IF (useGMRedi) CALL GMREDI_RTRANSPORT(  
      I     iMin,iMax,jMin,jMax,bi,bj,K,  
      I     maskUp,salt,  
      U     df,  
      I     myThid)  
 #endif  
136    
137  #ifdef ALLOW_KPP  #ifdef NONLIN_FRSURF
138  C--   Add non-local KPP transport term (ghat) to diffusive salt flux.        IF (nonlinFreeSurf.GT.0) THEN
139        IF (useKPP) CALL KPP_TRANSPORT_S(          CALL FREESURF_RESCALE_G(
140       I     iMin,iMax,jMin,jMax,bi,bj,k,km1,       I                          bi, bj, k,
141       I     maskC,KappaRS,       U                          gS,
142       U     df )       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
 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  
160        ENDIF        ENDIF
161    #endif /* NONLIN_FRSURF */
162    
163  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.  
 C     DO j=jMin,jMax  
 C      DO i=iMin,iMax  
       DO j=1-1,OLy+1  
        DO i=1-1,OLx+1  
 #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)  
164    
165        RETURN        RETURN
166        END        END

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

  ViewVC Help
Powered by ViewVC 1.1.22