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

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

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

revision 1.28 by jmc, Tue Feb 11 02:31:32 2003 UTC revision 1.29 by jmc, Tue Feb 18 15:30:47 2003 UTC
# Line 7  CBOP Line 7  CBOP
7  C     !ROUTINE: CALC_PHI_HYD  C     !ROUTINE: CALC_PHI_HYD
8  C     !INTERFACE:  C     !INTERFACE:
9        SUBROUTINE CALC_PHI_HYD(        SUBROUTINE CALC_PHI_HYD(
10       I                         bi, bj, iMin, iMax, jMin, jMax, K,       I                         bi, bj, iMin, iMax, jMin, jMax, k,
11       I                         tFld, sFld,       I                         tFld, sFld,
12       U                         phiHyd,       U                         phiHydF,
13       O                         dPhiHydX, dPhiHydY,       O                         phiHydC, dPhiHydX, dPhiHydY,
14       I                         myTime, myIter, myThid)       I                         myTime, myIter, myThid)
15  C     !DESCRIPTION: \bv  C     !DESCRIPTION: \bv
16  C     *==========================================================*  C     *==========================================================*
17  C     | SUBROUTINE CALC_PHI_HYD                                  |  C     | SUBROUTINE CALC_PHI_HYD                                  |
18  C     | o Integrate the hydrostatic relation to find the Hydros. |  C     | o Integrate the hydrostatic relation to find the Hydros. |
19  C     *==========================================================*  C     *==========================================================*
20  C     |    Potential (ocean: Pressure/rho ; atmos = geopotential)|  C     |    Potential (ocean: Pressure/rho ; atmos = geopotential)
21  C     | On entry:                                                |  C     | On entry:
22  C     |   tFld,sFld     are the current thermodynamics quantities|  C     |   tFld,sFld     are the current thermodynamics quantities
23  C     |                 (unchanged on exit)                      |  C     |                 (unchanged on exit)
24  C     |   phiHyd(i,j,1:k-1) is the hydrostatic Potential         |  C     |   phiHydF(i,j) is the hydrostatic Potential anomaly
25  C     |                 at cell centers (tracer points)          |  C     |                at middle between tracer points k-1,k
26  C     |                 - 1:k-1 layers are valid                 |  C     | On exit:
27  C     |                 - k:Nr layers are invalid                |  C     |   phiHydC(i,j) is the hydrostatic Potential anomaly
28  C     |   phiHyd(i,j,k) is the hydrostatic Potential             |  C     |                at cell centers (tracer points), level k
29  C     |  (ocean only_^) at cell the interface k (w point above)  |  C     |   phiHydF(i,j) is the hydrostatic Potential anomaly
30  C     | On exit:                                                 |  C     |                at middle between tracer points k,k+1
31  C     |   phiHyd(i,j,1:k) is the hydrostatic Potential           |  C     |   dPhiHydX,Y   hydrostatic Potential gradient (X&Y dir)
32  C     |                 at cell centers (tracer points)          |  C     |                at cell centers (tracer points), level k
33  C     |                 - 1:k layers are valid                   |  C     | integr_GeoPot allows to select one integration method
34  C     |                 - k+1:Nr layers are invalid              |  C     |    1= Finite volume form ; else= Finite difference form
 C     |   phiHyd(i,j,k+1) is the hydrostatic Potential (P/rho)   |  
 C     |  (ocean only-^) at cell the interface k+1 (w point below)|  
 C     | Atmosphere:                                              |  
 C     |   integr_GeoPot allows to select one integration method  |  
 C     |    (see the list below)                                  |  
35  C     *==========================================================*  C     *==========================================================*
36  C     \ev  C     \ev
37  C     !USES:  C     !USES:
# Line 46  C     == Global variables == Line 41  C     == Global variables ==
41  #include "GRID.h"  #include "GRID.h"
42  #include "EEPARAMS.h"  #include "EEPARAMS.h"
43  #include "PARAMS.h"  #include "PARAMS.h"
 c #include "FFIELDS.h"  
44  #ifdef ALLOW_AUTODIFF_TAMC  #ifdef ALLOW_AUTODIFF_TAMC
45  #include "tamc.h"  #include "tamc.h"
46  #include "tamc_keys.h"  #include "tamc_keys.h"
# Line 56  c #include "FFIELDS.h" Line 50  c #include "FFIELDS.h"
50    
51  C     !INPUT/OUTPUT PARAMETERS:  C     !INPUT/OUTPUT PARAMETERS:
52  C     == Routine arguments ==  C     == Routine arguments ==
53        INTEGER bi,bj,iMin,iMax,jMin,jMax,K  C     bi, bj, k  :: tile and level indices
54    C     iMin,iMax,jMin,jMax :: computational domain
55    C     tFld       :: potential temperature
56    C     sFld       :: salinity
57    C     phiHydF    :: hydrostatic potential anomaly at middle between
58    C                   2 centers (entry: Interf_k ; output: Interf_k+1)
59    C     phiHydC    :: hydrostatic potential anomaly at cell center
60    C     dPhiHydX,Y :: gradient (X & Y dir.) of hydrostatic potential anom.
61    C     myTime     :: current time
62    C     myIter     :: current iteration number
63    C     myThid     :: thread number for this instance of the routine.
64          INTEGER bi,bj,iMin,iMax,jMin,jMax,k
65        _RL tFld(1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr,nSx,nSy)        _RL tFld(1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr,nSx,nSy)
66        _RL sFld(1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr,nSx,nSy)        _RL sFld(1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr,nSx,nSy)
67        _RL phiHyd(1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr)  c     _RL phiHyd(1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr)
68          _RL phiHydF(1-OLx:sNx+OLx,1-OLy:sNy+OLy)
69          _RL phiHydC(1-OLx:sNx+OLx,1-OLy:sNy+OLy)
70        _RL dPhiHydX(1-Olx:sNx+Olx,1-Oly:sNy+Oly)        _RL dPhiHydX(1-Olx:sNx+Olx,1-Oly:sNy+Oly)
71        _RL dPhiHydY(1-Olx:sNx+Olx,1-Oly:sNy+Oly)        _RL dPhiHydY(1-Olx:sNx+Olx,1-Oly:sNy+Oly)
72        _RL myTime        _RL myTime
# Line 69  C     == Routine arguments == Line 76  C     == Routine arguments ==
76    
77  C     !LOCAL VARIABLES:  C     !LOCAL VARIABLES:
78  C     == Local variables ==  C     == Local variables ==
79        INTEGER i,j, Kp1        INTEGER i,j
80        _RL zero, one, half        _RL zero, one, half
81        _RL alphaRho(1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RL alphaRho(1-OLx:sNx+OLx,1-OLy:sNy+OLy)
82        _RL dRloc,dRlocKp1,locAlpha        _RL dRlocM,dRlocP, ddRloc, locAlpha
83        _RL ddPI, ddPIm, ddPIp, ratioRp, ratioRm        _RL ddPIm, ddPIp, rec_dRm, rec_dRp
84          _RL surfPhiFac
85        INTEGER iMnLoc,jMnLoc        INTEGER iMnLoc,jMnLoc
86        PARAMETER ( zero= 0. _d 0 , one= 1. _d 0 , half= .5 _d 0 )        PARAMETER ( zero= 0. _d 0 , one= 1. _d 0 , half= .5 _d 0 )
87        LOGICAL useDiagPhiRlow        LOGICAL useDiagPhiRlow, addSurfPhiAnom
88  CEOP  CEOP
89        useDiagPhiRlow = .TRUE.        useDiagPhiRlow = .TRUE.
90          addSurfPhiAnom = select_rStar.EQ.0 .AND. nonlinFreeSurf.GT.3
91          surfPhiFac = 0.
92          IF (addSurfPhiAnom) surfPhiFac = 1.
93    
94  C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|  C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
95  C  Atmosphere:    C  Atmosphere:  
96  C integr_GeoPot => select one option for the integration of the Geopotential:  C integr_GeoPot => select one option for the integration of the Geopotential:
97  C   = 0 : Energy Conserving Form, No hFac ;  C   = 0 : Energy Conserving Form, accurate with Topo full cell;
98  C   = 1 : Finite Volume Form, with hFac, linear in P by Half level;  C   = 1 : Finite Volume Form, with Part-Cell, linear in P by Half level;
99  C   =2,3: Finite Difference Form, with hFac, linear in P between 2 Tracer levels  C   =2,3: Finite Difference Form, with Part-Cell,
100  C     2 : case Tracer level at the middle of InterFace_W;  C         linear in P between 2 Tracer levels.
101  C     3 : case InterFace_W  at the middle of Tracer levels;  C       can handle both cases: Tracer lev at the middle of InterFace_W
102    C                          and InterFace_W at the middle of Tracer lev;
103  C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|  C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
104    
105  #ifdef ALLOW_AUTODIFF_TAMC  #ifdef ALLOW_AUTODIFF_TAMC
# Line 107  C---+----1----+----2----+----3----+----4 Line 119  C---+----1----+----2----+----3----+----4
119       &                      + act4*max1*max2*max3       &                      + act4*max1*max2*max3
120  #endif /* ALLOW_AUTODIFF_TAMC */  #endif /* ALLOW_AUTODIFF_TAMC */
121    
122    C--   Initialize phiHydF to zero :
123    C     note: atmospheric_loading or Phi_topo anomaly are incorporated
124    C           later in S/R calc_grad_phi_hyd
125          IF (k.EQ.1) THEN
126            DO j=1-Oly,sNy+Oly
127             DO i=1-Olx,sNx+Olx
128               phiHydF(i,j) = 0.
129             ENDDO
130            ENDDO
131          ENDIF
132    
133  C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|  C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
134        IF ( buoyancyRelation .eq. 'OCEANIC' ) THEN        IF ( buoyancyRelation .EQ. 'OCEANIC' ) THEN
135  C       This is the hydrostatic pressure calculation for the Ocean  C       This is the hydrostatic pressure calculation for the Ocean
136  C       which uses the FIND_RHO() routine to calculate density  C       which uses the FIND_RHO() routine to calculate density
137  C       before integrating g*rho over the current layer/interface  C       before integrating g*rho over the current layer/interface
# Line 117  C       before integrating g*rho over th Line 139  C       before integrating g*rho over th
139  CADJ GENERAL  CADJ GENERAL
140  #endif      /* ALLOW_AUTODIFF_TAMC */  #endif      /* ALLOW_AUTODIFF_TAMC */
141    
142          dRloc=drC(k)  C---    Calculate density
         IF (k.EQ.1) dRloc=drF(1)  
         IF (k.EQ.Nr) THEN  
           dRlocKp1=0.  
         ELSE  
           dRlocKp1=drC(k+1)  
         ENDIF  
   
 C--     If this is the top layer we impose the boundary condition  
 C       P(z=eta) = P(atmospheric_loading)  
         IF (k.EQ.1) THEN  
           DO j=jMin,jMax  
             DO i=iMin,iMax  
 c             phiHyd(i,j,k) = phi0surf(i,j,bi,bj)  
               phiHyd(i,j,k) = 0.  
             ENDDO  
           ENDDO  
         ENDIF  
   
 C       Calculate density  
143  #ifdef ALLOW_AUTODIFF_TAMC  #ifdef ALLOW_AUTODIFF_TAMC
144          kkey = (ikey-1)*Nr + k          kkey = (ikey-1)*Nr + k
145  CADJ STORE tFld (:,:,k,bi,bj) = comlev1_bibj_k, key=kkey, byte=isbyte  CADJ STORE tFld (:,:,k,bi,bj) = comlev1_bibj_k, key=kkey, byte=isbyte
# Line 151  C Quasi-hydrostatic terms are added in a Line 154  C Quasi-hydrostatic terms are added in a
154           CALL QUASIHYDROSTATICTERMS(bi,bj,k,alphaRho,myThid)           CALL QUASIHYDROSTATICTERMS(bi,bj,k,alphaRho,myThid)
155          ENDIF          ENDIF
156    
157  C---   Diagnose Hydrostatic pressure at the bottom:  #ifdef NONLIN_FRSURF
158         IF (useDiagPhiRlow) THEN          IF (k.EQ.1 .AND. addSurfPhiAnom) THEN
159            CALL DIAGS_PHI_RLOW(            DO j=jMin,jMax
160       I                        k, bi, bj, iMin,iMax, jMin,jMax,              DO i=iMin,iMax
161       I                        phiHyd, alphaRho, tFld, sFld,                phiHydF(i,j) = surfPhiFac*etaH(i,j,bi,bj)
162       I                        myTime, myIter, myThid)         &                      *gravity*alphaRho(i,j)*recip_rhoConst
163         ENDIF              ENDDO
164              ENDDO
165            ENDIF
166    #endif /* NONLIN_FRSURF */
167    
168  C---   Hydrostatic pressure at cell centers  C----  Hydrostatic pressure at cell centers
169    
170         IF (integr_GeoPot.EQ.1) THEN         IF (integr_GeoPot.EQ.1) THEN
171  C  --  Finite Volume Form  C  --  Finite Volume Form
# Line 171  C---------- This discretization is the " Line 177  C---------- This discretization is the "
177  C           which has not been used to date since it does not  C           which has not been used to date since it does not
178  C           conserve KE+PE exactly even though it is more natural  C           conserve KE+PE exactly even though it is more natural
179  C  C
180             IF (k.LT.Nr) phiHyd(i,j,k+1)=phiHyd(i,j,k)             phiHydC(i,j)=phiHydF(i,j)
181       &            + drF(K)*gravity*alphaRho(i,j)*recip_rhoConst       &       + half*drF(k)*gravity*alphaRho(i,j)*recip_rhoConst
182             phiHyd(i,j,k)=phiHyd(i,j,k)             phiHydF(i,j)=phiHydF(i,j)
183       &       + half*drF(K)*gravity*alphaRho(i,j)*recip_rhoConst       &            + drF(k)*gravity*alphaRho(i,j)*recip_rhoConst
   
184            ENDDO            ENDDO
185           ENDDO           ENDDO
186    
187         ELSE         ELSE
188  C  --  Finite Difference Form  C  --  Finite Difference Form
189    
190             dRlocM=half*drC(k)
191             IF (k.EQ.1) dRlocM=rF(k)-rC(k)
192             IF (k.EQ.Nr) THEN
193               dRlocP=rC(k)-rF(k+1)
194             ELSE
195               dRlocP=half*drC(k+1)
196             ENDIF
197    
198           DO j=jMin,jMax           DO j=jMin,jMax
199            DO i=iMin,iMax            DO i=iMin,iMax
200    
201  C---------- This discretization is the "energy conserving" form  C---------- This discretization is the "energy conserving" form
202  C           which has been used since at least Adcroft et al., MWR 1997  C           which has been used since at least Adcroft et al., MWR 1997
203  C  C
204              phiHyd(i,j,k)=phiHyd(i,j,k)              phiHydC(i,j)=phiHydF(i,j)
205       &        +half*dRloc*gravity*alphaRho(i,j)*recip_rhoConst       &        +dRlocM*gravity*alphaRho(i,j)*recip_rhoConst
206              IF (k.LT.Nr) phiHyd(i,j,k+1)=phiHyd(i,j,k)              phiHydF(i,j)=phiHydC(i,j)
207       &        +half*dRlocKp1*gravity*alphaRho(i,j)*recip_rhoConst       &        +dRlocP*gravity*alphaRho(i,j)*recip_rhoConst
   
208            ENDDO            ENDDO
209           ENDDO           ENDDO
210    
# Line 200  C  --  end if integr_GeoPot = ... Line 212  C  --  end if integr_GeoPot = ...
212         ENDIF         ENDIF
213                    
214  C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|  C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
215        ELSEIF ( buoyancyRelation .eq. 'OCEANICP' ) THEN        ELSEIF ( buoyancyRelation .EQ. 'OCEANICP' ) THEN
216  C       This is the hydrostatic pressure calculation for the Ocean  C       This is the hydrostatic pressure calculation for the Ocean
217  C       which uses the FIND_RHO() routine to calculate density  C       which uses the FIND_RHO() routine to calculate density
218  C       before integrating (1/rho)'*dp over the current layer/interface  C       before integrating (1/rho)'*dp over the current layer/interface
# Line 208  C       before integrating (1/rho)'*dp o Line 220  C       before integrating (1/rho)'*dp o
220  CADJ GENERAL  CADJ GENERAL
221  #endif      /* ALLOW_AUTODIFF_TAMC */  #endif      /* ALLOW_AUTODIFF_TAMC */
222    
         dRloc=drC(k)  
         IF (k.EQ.1) dRloc=drF(1)  
         IF (k.EQ.Nr) THEN  
           dRlocKp1=0.  
         ELSE  
           dRlocKp1=drC(k+1)  
         ENDIF  
   
         IF (k.EQ.1) THEN  
           DO j=jMin,jMax  
             DO i=iMin,iMax  
 c             phiHyd(i,j,k) = phi0surf(i,j,bi,bj)  
               phiHyd(i,j,k) = 0.  
             ENDDO  
           ENDDO  
         ENDIF  
   
223  C--     Calculate density  C--     Calculate density
224  #ifdef ALLOW_AUTODIFF_TAMC  #ifdef ALLOW_AUTODIFF_TAMC
225              kkey = (ikey-1)*Nr + k              kkey = (ikey-1)*Nr + k
# Line 247  C--     Calculate specific volume anomal Line 242  C--     Calculate specific volume anomal
242            ENDDO            ENDDO
243          ENDDO          ENDDO
244    
 C---   Diagnose Sea-surface height (Hydrostatic geopotential at r=Rlow):  
        IF (useDiagPhiRlow) THEN  
           CALL DIAGS_PHI_RLOW(  
      I                        k, bi, bj, iMin,iMax, jMin,jMax,  
      I                        phiHyd, alphaRho, tFld, sFld,  
      I                        myTime, myIter, myThid)    
        ENDIF  
   
245  C----  Hydrostatic pressure at cell centers  C----  Hydrostatic pressure at cell centers
246    
247         IF (integr_GeoPot.EQ.1) THEN         IF (integr_GeoPot.EQ.1) THEN
# Line 267  C---------- This discretization is the " Line 254  C---------- This discretization is the "
254  C           which has not been used to date since it does not  C           which has not been used to date since it does not
255  C           conserve KE+PE exactly even though it is more natural  C           conserve KE+PE exactly even though it is more natural
256  C  C
257              IF (k.LT.Nr) phiHyd(i,j,k+1)=phiHyd(i,j,k)             IF (k.EQ.ksurfC(i,j,bi,bj)) THEN
258       &          + hFacC(i,j,k,bi,bj)*drF(K)*alphaRho(i,j)               ddRloc = Ro_surf(i,j,bi,bj)-rC(k)
259              phiHyd(i,j,k)=phiHyd(i,j,k)  #ifdef NONLIN_FRSURF
260       &          +(hFacC(i,j,k,bi,bj)-half)*drF(K)*alphaRho(i,j)               ddRloc = ddRloc + surfPhiFac*etaH(i,j,bi,bj)
261    #endif
262                 phiHydC(i,j) = ddRloc*alphaRho(i,j)
263    c--to reproduce results of c48d_post: uncomment those 4+1 lines
264    c            phiHydC(i,j)=phiHydF(i,j)
265    c    &          +(hFacC(i,j,k,bi,bj)-half)*drF(k)*alphaRho(i,j)
266    c            phiHydF(i,j)=phiHydF(i,j)
267    c    &          + hFacC(i,j,k,bi,bj)*drF(k)*alphaRho(i,j)
268               ELSE
269                 phiHydC(i,j) = phiHydF(i,j) + half*drF(k)*alphaRho(i,j)
270    c            phiHydF(i,j) = phiHydF(i,j) +      drF(k)*alphaRho(i,j)
271               ENDIF
272    c-- and comment this last one:
273                 phiHydF(i,j) = phiHydC(i,j) + half*drF(k)*alphaRho(i,j)
274    c-----
275            ENDDO            ENDDO
276           ENDDO           ENDDO
277    
278         ELSE         ELSE
279  C  --  Finite Difference Form  C  --  Finite Difference Form, with Part-Cell Bathy
280    
281             dRlocM=half*drC(k)
282             IF (k.EQ.1) dRlocM=rF(k)-rC(k)
283             IF (k.EQ.Nr) THEN
284               dRlocP=rC(k)-rF(k+1)
285             ELSE
286               dRlocP=half*drC(k+1)
287             ENDIF
288             rec_dRm = one/(rF(k)-rC(k))
289             rec_dRp = one/(rC(k)-rF(k+1))
290    
291           DO j=jMin,jMax           DO j=jMin,jMax
292            DO i=iMin,iMax            DO i=iMin,iMax
293    
294  C---------- This discretization is the "energy conserving" form  C---------- This discretization is the "energy conserving" form
295    
296              phiHyd(i,j,k)=phiHyd(i,j,k)             IF (k.EQ.ksurfC(i,j,bi,bj)) THEN
297       &          + half*dRloc*alphaRho(i,j)               ddRloc = Ro_surf(i,j,bi,bj)-rC(k)
298              IF (k.LT.Nr) phiHyd(i,j,k+1)=phiHyd(i,j,k)  #ifdef NONLIN_FRSURF
299       &          + half*dRlocKp1*alphaRho(i,j)               ddRloc = ddRloc + surfPhiFac*etaH(i,j,bi,bj)
300    #endif
301                 phiHydC(i,j) =( MAX(zero,ddRloc)*rec_dRm*dRlocM
302         &                      +MIN(zero,ddRloc)*rec_dRp*dRlocP
303         &                     )*alphaRho(i,j)
304               ELSE
305                 phiHydC(i,j) = phiHydF(i,j) + dRlocM*alphaRho(i,j)
306               ENDIF
307                 phiHydF(i,j) = phiHydC(i,j) + dRlocP*alphaRho(i,j)
308            ENDDO            ENDDO
309           ENDDO           ENDDO
310    
311  C  --  end if integr_GeoPot = ...  C  --  end if integr_GeoPot = ...
312         ENDIF         ENDIF
313    
314        ELSEIF ( buoyancyRelation .eq. 'ATMOSPHERIC' ) THEN        ELSEIF ( buoyancyRelation .EQ. 'ATMOSPHERIC' ) THEN
315  C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|  C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
316  C       This is the hydrostatic geopotential calculation for the Atmosphere  C       This is the hydrostatic geopotential calculation for the Atmosphere
317  C       The ideal gas law is used implicitly here rather than calculating  C       The ideal gas law is used implicitly here rather than calculating
318  C       the specific volume, analogous to the oceanic case.  C       the specific volume, analogous to the oceanic case.
319    
320  C       Integrate d Phi / d pi  C---    Integrate d Phi / d pi
321    
322        IF (integr_GeoPot.EQ.0) THEN         IF (integr_GeoPot.EQ.0) THEN
323  C  --  Energy Conserving Form, No hFac  --  C  --  Energy Conserving Form, accurate with Full cell topo  --
324  C------------ The integration for the first level phi(k=1) is the same  C------------ The integration for the first level phi(k=1) is the same
325  C             for both the "finite volume" and energy conserving methods.  C             for both the "finite volume" and energy conserving methods.
326  Ci    *NOTE* o Working with geopotential Anomaly, the geopotential boundary  C    *NOTE* o Working with geopotential Anomaly, the geopotential boundary
327  C             condition is simply Phi-prime(Ro_surf)=0.  C             condition is simply Phi-prime(Ro_surf)=0.
328  C           o convention ddPI > 0 (same as drF & drC)  C           o convention ddPI > 0 (same as drF & drC)
329  C-----------------------------------------------------------------------  C-----------------------------------------------------------------------
330          IF (K.EQ.1) THEN           IF (k.EQ.1) THEN
331            ddPIp=atm_Cp*( ((rF(K)/atm_Po)**atm_kappa)             ddPIm=atm_Cp*( ((rF( k )/atm_Po)**atm_kappa)
332       &                  -((rC(K)/atm_Po)**atm_kappa) )       &                   -((rC( k )/atm_Po)**atm_kappa) )
333            DO j=jMin,jMax           ELSE
334             DO i=iMin,iMax             ddPIm=atm_Cp*( ((rC(k-1)/atm_Po)**atm_kappa)
335  c            phiHyd(i,j,K)= phi0surf(i,j,bi,bj)+       &                   -((rC( k )/atm_Po)**atm_kappa) )*half
336               phiHyd(i,j,K)=           ENDIF
337       &          ddPIp*maskC(i,j,K,bi,bj)           IF (k.EQ.Nr) THEN
338       &               *(tFld(I,J,K,bi,bj)-tRef(K))             ddPIp=atm_Cp*( ((rC( k )/atm_Po)**atm_kappa)
339             ENDDO       &                   -((rF(k+1)/atm_Po)**atm_kappa) )
340            ENDDO           ELSE
341          ELSE             ddPIp=atm_Cp*( ((rC( k )/atm_Po)**atm_kappa)
342         &                   -((rC(k+1)/atm_Po)**atm_kappa) )*half
343             ENDIF
344  C-------- This discretization is the energy conserving form  C-------- This discretization is the energy conserving form
345            ddPI=atm_Cp*( ((rC(K-1)/atm_Po)**atm_kappa)           DO j=jMin,jMax
346       &                 -((rC( K )/atm_Po)**atm_kappa) )*0.5            DO i=iMin,iMax
347            DO j=jMin,jMax               phiHydC(i,j) = phiHydF(i,j)
348             DO i=iMin,iMax       &          +ddPIm*maskC(i,j,k,bi,bj)
349                phiHyd(i,j,K)=phiHyd(i,j,K-1)       &                *(tFld(i,j,k,bi,bj)-tRef(k))
350       &           +ddPI*maskC(i,j,K-1,bi,bj)               phiHydF(i,j) = phiHydC(i,j)
351       &                *(tFld(I,J,K-1,bi,bj)-tRef(K-1))       &          +ddPIp*maskC(i,j,k,bi,bj)
352       &           +ddPI*maskC(i,j, K ,bi,bj)       &                *(tFld(i,j,k,bi,bj)-tRef(k))
      &                *(tFld(I,J, K ,bi,bj)-tRef( K ))  
 C             Old code (atmos-exact) looked like this  
 Cold          phiHyd(i,j,K)=phiHyd(i,j,K-1) - ddPI*  
 Cold &      (tFld(I,J,K-1,bi,bj)+tFld(I,J,K,bi,bj)-2.*tRef(K))  
            ENDDO  
353            ENDDO            ENDDO
354          ENDIF           ENDDO
355  C end: Energy Conserving Form, No hFac  --  C end: Energy Conserving Form, No hFac  --
356  C-----------------------------------------------------------------------  C-----------------------------------------------------------------------
357    
358        ELSEIF (integr_GeoPot.EQ.1) THEN         ELSEIF (integr_GeoPot.EQ.1) THEN
359  C  --  Finite Volume Form, with hFac, linear in P by Half level  --  C  --  Finite Volume Form, with Part-Cell Topo, linear in P by Half level
360  C---------  C---------
361  C  Finite Volume formulation consistent with Partial Cell, linear in p by piece  C  Finite Volume formulation consistent with Partial Cell, linear in p by piece
362  C   Note: a true Finite Volume form should be linear between 2 Interf_W :  C   Note: a true Finite Volume form should be linear between 2 Interf_W :
# Line 351  C   also: if Interface_W at the middle b Line 365  C   also: if Interface_W at the middle b
365  C     is close to the Energy Cons. form in the Interior, except for the  C     is close to the Energy Cons. form in the Interior, except for the
366  C     non-linearity in PI(p)  C     non-linearity in PI(p)
367  C---------  C---------
368          IF (K.EQ.1) THEN             ddPIm=atm_Cp*( ((rF( k )/atm_Po)**atm_kappa)
369            ddPIp=atm_Cp*( ((rF(K)/atm_Po)**atm_kappa)       &                   -((rC( k )/atm_Po)**atm_kappa) )
370       &                  -((rC(K)/atm_Po)**atm_kappa) )             ddPIp=atm_Cp*( ((rC( k )/atm_Po)**atm_kappa)
371            DO j=jMin,jMax       &                   -((rF(k+1)/atm_Po)**atm_kappa) )
372             DO i=iMin,iMax           DO j=jMin,jMax
373  c            phiHyd(i,j,K)= phi0surf(i,j,bi,bj)+            DO i=iMin,iMax
374               phiHyd(i,j,K)=             IF (k.EQ.ksurfC(i,j,bi,bj)) THEN
375       &          ddPIp*_hFacC(I,J, K ,bi,bj)               ddRloc = Ro_surf(i,j,bi,bj)-rC(k)
376       &               *(tFld(I,J, K ,bi,bj)-tRef( K ))  #ifdef NONLIN_FRSURF
377             ENDDO               ddRloc = ddRloc + surfPhiFac*etaH(i,j,bi,bj)
378            ENDDO  #endif
379          ELSE               phiHydC(i,j) = ddRloc*recip_drF(k)*2. _d 0
380            ddPIm=atm_Cp*( ((rC(K-1)/atm_Po)**atm_kappa)       &          *ddPIm*maskC(i,j,k,bi,bj)
381       &                  -((rF( K )/atm_Po)**atm_kappa) )       &                *(tFld(i,j,k,bi,bj)-tRef(k))
382            ddPIp=atm_Cp*( ((rF( K )/atm_Po)**atm_kappa)             ELSE
383       &                  -((rC( K )/atm_Po)**atm_kappa) )               phiHydC(i,j) = phiHydF(i,j)
384            DO j=jMin,jMax       &          +ddPIm*maskC(i,j,k,bi,bj)
385             DO i=iMin,iMax       &                *(tFld(i,j,k,bi,bj)-tRef(k))
386               phiHyd(i,j,K) = phiHyd(i,j,K-1)             ENDIF
387       &         +ddPIm*_hFacC(I,J,K-1,bi,bj)               phiHydF(i,j) = phiHydC(i,j)
388       &               *(tFld(I,J,K-1,bi,bj)-tRef(K-1))       &          +ddPIp*maskC(i,j,k,bi,bj)
389       &         +ddPIp*_hFacC(I,J, K ,bi,bj)       &                *(tFld(i,j,k,bi,bj)-tRef(k))
      &               *(tFld(I,J, K ,bi,bj)-tRef( K ))  
            ENDDO  
           ENDDO  
         ENDIF  
 C end: Finite Volume Form, with hFac, linear in P by Half level  --  
 C-----------------------------------------------------------------------  
   
       ELSEIF (integr_GeoPot.EQ.2) THEN  
 C  --  Finite Difference Form, with hFac, Tracer Lev. = middle  --  
 C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|  
 C  Finite Difference formulation consistent with Partial Cell,  
 C    case Tracer level at the middle of InterFace_W  
 C    linear between 2 Tracer levels ; conserve energy in the Interior  
 C---------  
         Kp1 = min(Nr,K+1)  
         IF (K.EQ.1) THEN  
           ddPIm=atm_Cp*( ((rF( K )/atm_Po)**atm_kappa)  
      &                  -((rC( K )/atm_Po)**atm_kappa) ) * 2. _d 0  
           ddPIp=atm_Cp*( ((rC( K )/atm_Po)**atm_kappa)  
      &                  -((rC(Kp1)/atm_Po)**atm_kappa) )    
           DO j=jMin,jMax  
            DO i=iMin,iMax  
 c            phiHyd(i,j,K)= phi0surf(i,j,bi,bj)+  
              phiHyd(i,j,K)=  
      &        ( ddPIm*max(zero, _hFacC(i,j,K,bi,bj)-half)  
      &         +ddPIp*min(zero, _hFacC(i,j,K,bi,bj)-half) )  
      &               *(tFld(i,j, K ,bi,bj)-tRef( K ))  
      &               * maskC(i,j, K ,bi,bj)  
            ENDDO  
           ENDDO  
         ELSE  
           ddPIm=atm_Cp*( ((rC(K-1)/atm_Po)**atm_kappa)  
      &                  -((rC( K )/atm_Po)**atm_kappa) )  
           ddPIp=atm_Cp*( ((rC( K )/atm_Po)**atm_kappa)  
      &                  -((rC(Kp1)/atm_Po)**atm_kappa) )  
           DO j=jMin,jMax  
            DO i=iMin,iMax  
              phiHyd(i,j,K) = phiHyd(i,j,K-1)  
      &        + ddPIm*0.5  
      &               *(tFld(i,j,K-1,bi,bj)-tRef(K-1))  
      &               * maskC(i,j,K-1,bi,bj)  
      &        +(ddPIm*max(zero, _hFacC(i,j,K,bi,bj)-half)  
      &         +ddPIp*min(zero, _hFacC(i,j,K,bi,bj)-half) )  
      &               *(tFld(i,j, K ,bi,bj)-tRef( K ))  
      &               * maskC(i,j, K ,bi,bj)  
            ENDDO  
390            ENDDO            ENDDO
391          ENDIF           ENDDO
392  C end: Finite Difference Form, with hFac, Tracer Lev. = middle  --  C end: Finite Volume Form, with Part-Cell Topo, linear in P by Half level
393  C-----------------------------------------------------------------------  C-----------------------------------------------------------------------
394    
395        ELSEIF (integr_GeoPot.EQ.3) THEN         ELSEIF ( integr_GeoPot.EQ.2
396  C  --  Finite Difference Form, with hFac, Interface_W = middle  --       &     .OR. integr_GeoPot.EQ.3 ) THEN
397    C  --  Finite Difference Form, with Part-Cell Topo,
398    C       works with Interface_W  at the middle between 2.Tracer_Level
399    C        and  with Tracer_Level at the middle between 2.Interface_W.
400  C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|  C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
401  C  Finite Difference formulation consistent with Partial Cell,  C  Finite Difference formulation consistent with Partial Cell,
402  C   Valid & accurate if Interface_W at middle between tracer levels  C   Valid & accurate if Interface_W at middle between tracer levels
403  C   linear in p between 2 Tracer levels ; conserve energy in the Interior  C   linear in p between 2 Tracer levels ; conserve energy in the Interior
404  C---------  C---------
405          Kp1 = min(Nr,K+1)           IF (k.EQ.1) THEN
406          IF (K.EQ.1) THEN             ddPIm=atm_Cp*( ((rF( k )/atm_Po)**atm_kappa)
407            ratioRm=0.5*drF(K)/(rF(k)-rC(K))       &                   -((rC( k )/atm_Po)**atm_kappa) )
408            ratioRp=drF(K)*recip_drC(Kp1)           ELSE
409            ddPIm=atm_Cp*( ((rF( K )/atm_Po)**atm_kappa)             ddPIm=atm_Cp*( ((rC(k-1)/atm_Po)**atm_kappa)
410       &                  -((rC( K )/atm_Po)**atm_kappa) ) * 2. _d 0       &                   -((rC( k )/atm_Po)**atm_kappa) )*half
411            ddPIp=atm_Cp*( ((rC( K )/atm_Po)**atm_kappa)           ENDIF
412       &                  -((rC(Kp1)/atm_Po)**atm_kappa) )             IF (k.EQ.Nr) THEN
413            DO j=jMin,jMax             ddPIp=atm_Cp*( ((rC( k )/atm_Po)**atm_kappa)
414             DO i=iMin,iMax       &                   -((rF(k+1)/atm_Po)**atm_kappa) )
415  c            phiHyd(i,j,K)= phi0surf(i,j,bi,bj)+           ELSE
416               phiHyd(i,j,K)=             ddPIp=atm_Cp*( ((rC( k )/atm_Po)**atm_kappa)
417       &        ( ddPIm*max(zero,(_hFacC(i,j,K,bi,bj)-one)*ratioRm+half)       &                   -((rC(k+1)/atm_Po)**atm_kappa) )*half
418       &         +ddPIp*min(zero, _hFacC(i,j,K,bi,bj)*ratioRp     -half) )           ENDIF
419       &               *(tFld(i,j, K ,bi,bj)-tRef( K ))           rec_dRm = one/(rF(k)-rC(k))
420       &               * maskC(i,j, K ,bi,bj)           rec_dRp = one/(rC(k)-rF(k+1))
421             ENDDO           DO j=jMin,jMax
422            ENDDO            DO i=iMin,iMax
423          ELSE             IF (k.EQ.ksurfC(i,j,bi,bj)) THEN
424            ratioRm=drF(K)*recip_drC(K)               ddRloc = Ro_surf(i,j,bi,bj)-rC(k)
425            ratioRp=drF(K)*recip_drC(Kp1)  #ifdef NONLIN_FRSURF
426            ddPIm=atm_Cp*( ((rC(K-1)/atm_Po)**atm_kappa)               ddRloc = ddRloc + surfPhiFac*etaH(i,j,bi,bj)
427       &                  -((rC( K )/atm_Po)**atm_kappa) )  #endif
428            ddPIp=atm_Cp*( ((rC( K )/atm_Po)**atm_kappa)               phiHydC(i,j) =( MAX(zero,ddRloc)*rec_dRm*ddPIm
429       &                  -((rC(Kp1)/atm_Po)**atm_kappa) )       &                      +MIN(zero,ddRloc)*rec_dRp*ddPIp )
430            DO j=jMin,jMax       &                *(tFld(i,j,k,bi,bj)-tRef(k))
431             DO i=iMin,iMax             ELSE
432               phiHyd(i,j,K) = phiHyd(i,j,K-1)               phiHydC(i,j) = phiHydF(i,j)
433       &        + ddPIm*0.5       &          +ddPIm*maskC(i,j,k,bi,bj)
434       &               *(tFld(i,j,K-1,bi,bj)-tRef(K-1))       &                *(tFld(I,J,k,bi,bj)-tRef(k))
435       &               * maskC(i,j,K-1,bi,bj)             ENDIF
436       &        +(ddPIm*max(zero,(_hFacC(i,j,K,bi,bj)-one)*ratioRm+half)               phiHydF(i,j) = phiHydC(i,j)
437       &         +ddPIp*min(zero, _hFacC(i,j,K,bi,bj)*ratioRp     -half) )       &          +ddPIp*maskC(i,j,k,bi,bj)
438       &               *(tFld(i,j, K ,bi,bj)-tRef( K ))       &                *(tFld(I,J,k,bi,bj)-tRef(k))
      &               * maskC(i,j, K ,bi,bj)  
            ENDDO  
439            ENDDO            ENDDO
440          ENDIF           ENDDO
441  C end: Finite Difference Form, with hFac, Interface_W = middle  --  C end: Finite Difference Form, with Part-Cell Topo
442  C-----------------------------------------------------------------------  C-----------------------------------------------------------------------
443    
444        ELSE         ELSE
445          STOP 'CALC_PHI_HYD: Bad integr_GeoPot option !'           STOP 'CALC_PHI_HYD: Bad integr_GeoPot option !'
446        ENDIF         ENDIF
447    
448  C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|  C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
449        ELSE        ELSE
450          STOP 'CALC_PHI_HYD: Bad value of buoyancyRelation !'          STOP 'CALC_PHI_HYD: Bad value of buoyancyRelation !'
451        ENDIF        ENDIF
452    
453    C---   Diagnose Phi at boundary r=R_low :
454    C       = Ocean bottom pressure (Ocean, Z-coord.)
455    C       = Sea-surface height    (Ocean, P-coord.)
456    C       = Top atmosphere height (Atmos, P-coord.)
457          IF (useDiagPhiRlow) THEN
458            CALL DIAGS_PHI_RLOW(
459         I                      k, bi, bj, iMin,iMax, jMin,jMax,
460         I                      phiHydF, phiHydC, alphaRho, tFld, sFld,
461         I                      myTime, myIter, myThid)  
462          ENDIF
463    
464    C---   Diagnose Full Hydrostatic Potential at cell center level
465            CALL DIAGS_PHI_HYD(
466         I                      k, bi, bj, iMin,iMax, jMin,jMax,
467         I                      phiHydC,
468         I                      myTime, myIter, myThid)
469    
470        IF (momPressureForcing) THEN        IF (momPressureForcing) THEN
471          iMnLoc = MAX(1-Olx+1,iMin)          iMnLoc = MAX(1-Olx+1,iMin)
472          jMnLoc = MAX(1-Oly+1,jMin)          jMnLoc = MAX(1-Oly+1,jMin)
473          CALL CALC_GRAD_PHI_HYD(          CALL CALC_GRAD_PHI_HYD(
474       I                         k, bi, bj, iMnLoc,iMax, jMnLoc,jMax,       I                         k, bi, bj, iMnLoc,iMax, jMnLoc,jMax,
475       I                         phiHyd, alphaRho, tFld, sFld,       I                         phiHydC, alphaRho, tFld, sFld,
476       O                         dPhiHydX, dPhiHydY,       O                         dPhiHydX, dPhiHydY,
477       I                         myTime, myIter, myThid)         I                         myTime, myIter, myThid)  
478        ENDIF        ENDIF

Legend:
Removed from v.1.28  
changed lines
  Added in v.1.29

  ViewVC Help
Powered by ViewVC 1.1.22