/[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.38 by jmc, Mon Sep 22 17:55:16 2008 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  CBOP  CBOP
8  C     !ROUTINE: CALC_PHI_HYD  C     !ROUTINE: CALC_PHI_HYD
9  C     !INTERFACE:  C     !INTERFACE:
10        SUBROUTINE CALC_PHI_HYD(        SUBROUTINE CALC_PHI_HYD(
11       I                         bi, bj, iMin, iMax, jMin, jMax, K,       I                         bi, bj, iMin, iMax, jMin, jMax, k,
12       I                         tFld, sFld,       I                         tFld, sFld,
13       U                         phiHyd,       U                         phiHydF,
14       O                         dPhiHydX, dPhiHydY,       O                         phiHydC, dPhiHydX, dPhiHydY,
15       I                         myTime, myIter, myThid)       I                         myTime, myIter, myThid )
16  C     !DESCRIPTION: \bv  C     !DESCRIPTION: \bv
17  C     *==========================================================*  C     *==========================================================*
18  C     | SUBROUTINE CALC_PHI_HYD                                  |  C     | SUBROUTINE CALC_PHI_HYD                                  |
19  C     | o Integrate the hydrostatic relation to find the Hydros. |  C     | o Integrate the hydrostatic relation to find the Hydros. |
20  C     *==========================================================*  C     *==========================================================*
21  C     |    Potential (ocean: Pressure/rho ; atmos = geopotential)|  C     |    Potential (ocean: Pressure/rho ; atmos = geopotential)
22  C     | On entry:                                                |  C     | On entry:
23  C     |   tFld,sFld     are the current thermodynamics quantities|  C     |   tFld,sFld     are the current thermodynamics quantities
24  C     |                 (unchanged on exit)                      |  C     |                 (unchanged on exit)
25  C     |   phiHyd(i,j,1:k-1) is the hydrostatic Potential         |  C     |   phiHydF(i,j) is the hydrostatic Potential anomaly
26  C     |                 at cell centers (tracer points)          |  C     |                at middle between tracer points k-1,k
27  C     |                 - 1:k-1 layers are valid                 |  C     | On exit:
28  C     |                 - k:Nr layers are invalid                |  C     |   phiHydC(i,j) is the hydrostatic Potential anomaly
29  C     |   phiHyd(i,j,k) is the hydrostatic Potential             |  C     |                at cell centers (tracer points), level k
30  C     |  (ocean only_^) at cell the interface k (w point above)  |  C     |   phiHydF(i,j) is the hydrostatic Potential anomaly
31  C     | On exit:                                                 |  C     |                at middle between tracer points k,k+1
32  C     |   phiHyd(i,j,1:k) is the hydrostatic Potential           |  C     |   dPhiHydX,Y   hydrostatic Potential gradient (X&Y dir)
33  C     |                 at cell centers (tracer points)          |  C     |                at cell centers (tracer points), level k
34  C     |                 - 1:k layers are valid                   |  C     | integr_GeoPot allows to select one integration method
35  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)                                  |  
36  C     *==========================================================*  C     *==========================================================*
37  C     \ev  C     \ev
38  C     !USES:  C     !USES:
# Line 46  C     == Global variables == Line 42  C     == Global variables ==
42  #include "GRID.h"  #include "GRID.h"
43  #include "EEPARAMS.h"  #include "EEPARAMS.h"
44  #include "PARAMS.h"  #include "PARAMS.h"
 c #include "FFIELDS.h"  
45  #ifdef ALLOW_AUTODIFF_TAMC  #ifdef ALLOW_AUTODIFF_TAMC
46  #include "tamc.h"  #include "tamc.h"
47  #include "tamc_keys.h"  #include "tamc_keys.h"
# Line 56  c #include "FFIELDS.h" Line 51  c #include "FFIELDS.h"
51    
52  C     !INPUT/OUTPUT PARAMETERS:  C     !INPUT/OUTPUT PARAMETERS:
53  C     == Routine arguments ==  C     == Routine arguments ==
54        INTEGER bi,bj,iMin,iMax,jMin,jMax,K  C     bi, bj, k  :: tile and level indices
55    C     iMin,iMax,jMin,jMax :: computational domain
56    C     tFld       :: potential temperature
57    C     sFld       :: salinity
58    C     phiHydF    :: hydrostatic potential anomaly at middle between
59    C                   2 centers (entry: Interf_k ; output: Interf_k+1)
60    C     phiHydC    :: hydrostatic potential anomaly at cell center
61    C     dPhiHydX,Y :: gradient (X & Y dir.) of hydrostatic potential anom.
62    C     myTime     :: current time
63    C     myIter     :: current iteration number
64    C     myThid     :: thread number for this instance of the routine.
65          INTEGER bi,bj,iMin,iMax,jMin,jMax,k
66        _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)
67        _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)
68        _RL phiHyd(1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr)  c     _RL phiHyd(1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr)
69          _RL phiHydF(1-OLx:sNx+OLx,1-OLy:sNy+OLy)
70          _RL phiHydC(1-OLx:sNx+OLx,1-OLy:sNy+OLy)
71        _RL dPhiHydX(1-Olx:sNx+Olx,1-Oly:sNy+Oly)        _RL dPhiHydX(1-Olx:sNx+Olx,1-Oly:sNy+Oly)
72        _RL dPhiHydY(1-Olx:sNx+Olx,1-Oly:sNy+Oly)        _RL dPhiHydY(1-Olx:sNx+Olx,1-Oly:sNy+Oly)
73        _RL myTime        _RL myTime
74        INTEGER myIter, myThid        INTEGER myIter, myThid
75          
76  #ifdef INCLUDE_PHIHYD_CALCULATION_CODE  #ifdef INCLUDE_PHIHYD_CALCULATION_CODE
77    
78  C     !LOCAL VARIABLES:  C     !LOCAL VARIABLES:
79  C     == Local variables ==  C     == Local variables ==
80        INTEGER i,j, Kp1        INTEGER i,j
81        _RL zero, one, half        _RL zero, one, half
82        _RL alphaRho(1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RL alphaRho(1-OLx:sNx+OLx,1-OLy:sNy+OLy)
83        _RL dRloc,dRlocKp1,locAlpha        _RL dRlocM,dRlocP, ddRloc, locAlpha
84        _RL ddPI, ddPIm, ddPIp, ratioRp, ratioRm        _RL ddPIm, ddPIp, rec_dRm, rec_dRp
85        INTEGER iMnLoc,jMnLoc        _RL surfPhiFac
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
138  #ifdef      ALLOW_AUTODIFF_TAMC  #ifdef ALLOW_AUTODIFF_TAMC
139  CADJ GENERAL  CADJ GENERAL
140  #endif      /* ALLOW_AUTODIFF_TAMC */  #endif /* ALLOW_AUTODIFF_TAMC */
141    
142          dRloc=drC(k)          IF ( implicitIntGravWave .OR. myIter.LT.0 ) THEN
143          IF (k.EQ.1) dRloc=drF(1)  C---    Calculate density
144          IF (k.EQ.Nr) THEN  #ifdef ALLOW_AUTODIFF_TAMC
145            dRlocKp1=0.            kkey = (ikey-1)*Nr + k
146    CADJ STORE tFld (:,:,k,bi,bj) = comlev1_bibj_k, key=kkey, byte=isbyte
147    CADJ STORE sFld (:,:,k,bi,bj) = comlev1_bibj_k, key=kkey, byte=isbyte
148    #endif /* ALLOW_AUTODIFF_TAMC */
149              CALL FIND_RHO_2D(
150         I              iMin, iMax, jMin, jMax, k,
151         I              tFld(1-OLx,1-OLy,k,bi,bj),
152         I              sFld(1-OLx,1-OLy,k,bi,bj),
153         O              alphaRho,
154         I              k, bi, bj, myThid )
155          ELSE          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  
156            DO j=jMin,jMax            DO j=jMin,jMax
157              DO i=iMin,iMax             DO i=iMin,iMax
158  c             phiHyd(i,j,k) = phi0surf(i,j,bi,bj)               alphaRho(i,j) = rhoInSitu(i,j,k,bi,bj)
159                phiHyd(i,j,k) = 0.             ENDDO
             ENDDO  
160            ENDDO            ENDDO
161          ENDIF          ENDIF
162    
163  C       Calculate density  #ifdef ALLOW_SHELFICE
164  #ifdef ALLOW_AUTODIFF_TAMC  C     mask rho, so that there is no contribution of phiHyd from
165          kkey = (ikey-1)*Nr + k  C     overlying shelfice (whose density we do not know)
166  CADJ STORE tFld (:,:,k,bi,bj) = comlev1_bibj_k, key=kkey, byte=isbyte          IF ( useShelfIce .AND. useDOWN_SLOPE ) THEN
167  CADJ STORE sFld (:,:,k,bi,bj) = comlev1_bibj_k, key=kkey, byte=isbyte  C- note: does not work for down_slope pkg which needs rho below the bottom.
168  #endif /* ALLOW_AUTODIFF_TAMC */  C    setting rho=0 above the ice-shelf base is enough (and works in both cases)
169          CALL FIND_RHO( bi, bj, iMin, iMax, jMin, jMax, k, k,  C    but might be slower (--> keep original masking if not using down_slope pkg)
170       &                 tFld, sFld,           DO j=jMin,jMax
171       &                 alphaRho, myThid)            DO i=iMin,iMax
172               IF ( k.LT.kSurfC(i,j,bi,bj) ) alphaRho(i,j) = 0. _d 0
173              ENDDO
174             ENDDO
175            ELSEIF ( useShelfIce ) THEN
176             DO j=jMin,jMax
177              DO i=iMin,iMax
178               alphaRho(i,j) = alphaRho(i,j)*maskC(i,j,k,bi,bj)
179              ENDDO
180             ENDDO
181            ENDIF
182    #endif /* ALLOW_SHELFICE */
183    
184    #ifdef ALLOW_MOM_COMMON
185  C Quasi-hydrostatic terms are added in as if they modify the buoyancy  C Quasi-hydrostatic terms are added in as if they modify the buoyancy
186          IF (quasiHydrostatic) THEN          IF (quasiHydrostatic) THEN
187           CALL QUASIHYDROSTATICTERMS(bi,bj,k,alphaRho,myThid)           CALL MOM_QUASIHYDROSTATIC(bi,bj,k,uVel,vVel,alphaRho,myThid)
188          ENDIF          ENDIF
189    #endif /* ALLOW_MOM_COMMON */
190    
191  C---   Diagnose Hydrostatic pressure at the bottom:  #ifdef NONLIN_FRSURF
192         IF (useDiagPhiRlow) THEN          IF (k.EQ.1 .AND. addSurfPhiAnom) THEN
193            CALL DIAGS_PHI_RLOW(            DO j=jMin,jMax
194       I                        k, bi, bj, iMin,iMax, jMin,jMax,              DO i=iMin,iMax
195       I                        phiHyd, alphaRho, tFld, sFld,                phiHydF(i,j) = surfPhiFac*etaH(i,j,bi,bj)
196       I                        myTime, myIter, myThid)         &                      *gravity*alphaRho(i,j)*recip_rhoConst
197         ENDIF              ENDDO
198              ENDDO
199            ENDIF
200    #endif /* NONLIN_FRSURF */
201    
202  C---   Hydrostatic pressure at cell centers  C----  Hydrostatic pressure at cell centers
203    
204         IF (integr_GeoPot.EQ.1) THEN         IF (integr_GeoPot.EQ.1) THEN
205  C  --  Finite Volume Form  C  --  Finite Volume Form
# Line 171  C---------- This discretization is the " Line 211  C---------- This discretization is the "
211  C           which has not been used to date since it does not  C           which has not been used to date since it does not
212  C           conserve KE+PE exactly even though it is more natural  C           conserve KE+PE exactly even though it is more natural
213  C  C
214             IF (k.LT.Nr) phiHyd(i,j,k+1)=phiHyd(i,j,k)             phiHydC(i,j)=phiHydF(i,j)
215       &            + drF(K)*gravity*alphaRho(i,j)*recip_rhoConst       &       + half*drF(k)*gravity*alphaRho(i,j)*recip_rhoConst
216             phiHyd(i,j,k)=phiHyd(i,j,k)             phiHydF(i,j)=phiHydF(i,j)
217       &       + half*drF(K)*gravity*alphaRho(i,j)*recip_rhoConst       &            + drF(k)*gravity*alphaRho(i,j)*recip_rhoConst
   
218            ENDDO            ENDDO
219           ENDDO           ENDDO
220    
221         ELSE         ELSE
222  C  --  Finite Difference Form  C  --  Finite Difference Form
223    
224             dRlocM=half*drC(k)
225             IF (k.EQ.1) dRlocM=rF(k)-rC(k)
226             IF (k.EQ.Nr) THEN
227               dRlocP=rC(k)-rF(k+1)
228             ELSE
229               dRlocP=half*drC(k+1)
230             ENDIF
231    
232           DO j=jMin,jMax           DO j=jMin,jMax
233            DO i=iMin,iMax            DO i=iMin,iMax
234    
235  C---------- This discretization is the "energy conserving" form  C---------- This discretization is the "energy conserving" form
236  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
237  C  C
238              phiHyd(i,j,k)=phiHyd(i,j,k)              phiHydC(i,j)=phiHydF(i,j)
239       &        +half*dRloc*gravity*alphaRho(i,j)*recip_rhoConst       &        +dRlocM*gravity*alphaRho(i,j)*recip_rhoConst
240              IF (k.LT.Nr) phiHyd(i,j,k+1)=phiHyd(i,j,k)              phiHydF(i,j)=phiHydC(i,j)
241       &        +half*dRlocKp1*gravity*alphaRho(i,j)*recip_rhoConst       &        +dRlocP*gravity*alphaRho(i,j)*recip_rhoConst
   
242            ENDDO            ENDDO
243           ENDDO           ENDDO
244    
245  C  --  end if integr_GeoPot = ...  C  --  end if integr_GeoPot = ...
246         ENDIF         ENDIF
247            
248  C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|  C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
249        ELSEIF ( buoyancyRelation .eq. 'OCEANICP' ) THEN        ELSEIF ( buoyancyRelation .EQ. 'OCEANICP' ) THEN
250  C       This is the hydrostatic pressure calculation for the Ocean  C       This is the hydrostatic pressure calculation for the Ocean
251  C       which uses the FIND_RHO() routine to calculate density  C       which uses the FIND_RHO() routine to calculate density
252  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 254  C       before integrating (1/rho)'*dp o
254  CADJ GENERAL  CADJ GENERAL
255  #endif      /* ALLOW_AUTODIFF_TAMC */  #endif      /* ALLOW_AUTODIFF_TAMC */
256    
257          dRloc=drC(k)          IF ( implicitIntGravWave .OR. myIter.LT.0 ) THEN
         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  
   
258  C--     Calculate density  C--     Calculate density
259  #ifdef ALLOW_AUTODIFF_TAMC  #ifdef ALLOW_AUTODIFF_TAMC
260              kkey = (ikey-1)*Nr + k            kkey = (ikey-1)*Nr + k
261  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
262  CADJ STORE sFld (:,:,k,bi,bj) = comlev1_bibj_k, key=kkey, byte=isbyte  CADJ STORE sFld (:,:,k,bi,bj) = comlev1_bibj_k, key=kkey, byte=isbyte
263  #endif /* ALLOW_AUTODIFF_TAMC */  #endif /* ALLOW_AUTODIFF_TAMC */
264          CALL FIND_RHO( bi, bj, iMin, iMax, jMin, jMax, k, k,            CALL FIND_RHO_2D(
265       &                 tFld, sFld,       I              iMin, iMax, jMin, jMax, k,
266       &                 alphaRho, myThid)       I              tFld(1-OLx,1-OLy,k,bi,bj),
267         I              sFld(1-OLx,1-OLy,k,bi,bj),
268         O              alphaRho,
269         I              k, bi, bj, myThid )
270  #ifdef ALLOW_AUTODIFF_TAMC  #ifdef ALLOW_AUTODIFF_TAMC
271  CADJ STORE alphaRho (:,:) = comlev1_bibj_k, key=kkey, byte=isbyte  CADJ STORE alphaRho (:,:) = comlev1_bibj_k, key=kkey, byte=isbyte
272  #endif /* ALLOW_AUTODIFF_TAMC */  #endif /* ALLOW_AUTODIFF_TAMC */
273            ELSE
274              DO j=jMin,jMax
275               DO i=iMin,iMax
276                 alphaRho(i,j) = rhoInSitu(i,j,k,bi,bj)
277               ENDDO
278              ENDDO
279            ENDIF
280    
281  C--     Calculate specific volume anomaly : alpha' = 1/rho - alpha_Cst  C--     Calculate specific volume anomaly : alpha' = 1/rho - alpha_Cst
282          DO j=jMin,jMax          DO j=jMin,jMax
# Line 247  C--     Calculate specific volume anomal Line 287  C--     Calculate specific volume anomal
287            ENDDO            ENDDO
288          ENDDO          ENDDO
289    
 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  
   
290  C----  Hydrostatic pressure at cell centers  C----  Hydrostatic pressure at cell centers
291    
292         IF (integr_GeoPot.EQ.1) THEN         IF (integr_GeoPot.EQ.1) THEN
# Line 267  C---------- This discretization is the " Line 299  C---------- This discretization is the "
299  C           which has not been used to date since it does not  C           which has not been used to date since it does not
300  C           conserve KE+PE exactly even though it is more natural  C           conserve KE+PE exactly even though it is more natural
301  C  C
302              IF (k.LT.Nr) phiHyd(i,j,k+1)=phiHyd(i,j,k)             IF (k.EQ.kSurfC(i,j,bi,bj)) THEN
303       &          + hFacC(i,j,k,bi,bj)*drF(K)*alphaRho(i,j)               ddRloc = Ro_surf(i,j,bi,bj)-rC(k)
304              phiHyd(i,j,k)=phiHyd(i,j,k)  #ifdef NONLIN_FRSURF
305       &          +(hFacC(i,j,k,bi,bj)-half)*drF(K)*alphaRho(i,j)               ddRloc = ddRloc + surfPhiFac*etaH(i,j,bi,bj)
306    #endif
307                 phiHydC(i,j) = ddRloc*alphaRho(i,j)
308    c--to reproduce results of c48d_post: uncomment those 4+1 lines
309    c            phiHydC(i,j)=phiHydF(i,j)
310    c    &          +(hFacC(i,j,k,bi,bj)-half)*drF(k)*alphaRho(i,j)
311    c            phiHydF(i,j)=phiHydF(i,j)
312    c    &          + hFacC(i,j,k,bi,bj)*drF(k)*alphaRho(i,j)
313               ELSE
314                 phiHydC(i,j) = phiHydF(i,j) + half*drF(k)*alphaRho(i,j)
315    c            phiHydF(i,j) = phiHydF(i,j) +      drF(k)*alphaRho(i,j)
316               ENDIF
317    c-- and comment this last one:
318                 phiHydF(i,j) = phiHydC(i,j) + half*drF(k)*alphaRho(i,j)
319    c-----
320            ENDDO            ENDDO
321           ENDDO           ENDDO
322    
323         ELSE         ELSE
324  C  --  Finite Difference Form  C  --  Finite Difference Form, with Part-Cell Bathy
325    
326             dRlocM=half*drC(k)
327             IF (k.EQ.1) dRlocM=rF(k)-rC(k)
328             IF (k.EQ.Nr) THEN
329               dRlocP=rC(k)-rF(k+1)
330             ELSE
331               dRlocP=half*drC(k+1)
332             ENDIF
333             rec_dRm = one/(rF(k)-rC(k))
334             rec_dRp = one/(rC(k)-rF(k+1))
335    
336           DO j=jMin,jMax           DO j=jMin,jMax
337            DO i=iMin,iMax            DO i=iMin,iMax
338    
339  C---------- This discretization is the "energy conserving" form  C---------- This discretization is the "energy conserving" form
340    
341              phiHyd(i,j,k)=phiHyd(i,j,k)             IF (k.EQ.kSurfC(i,j,bi,bj)) THEN
342       &          + half*dRloc*alphaRho(i,j)               ddRloc = Ro_surf(i,j,bi,bj)-rC(k)
343              IF (k.LT.Nr) phiHyd(i,j,k+1)=phiHyd(i,j,k)  #ifdef NONLIN_FRSURF
344       &          + half*dRlocKp1*alphaRho(i,j)               ddRloc = ddRloc + surfPhiFac*etaH(i,j,bi,bj)
345    #endif
346                 phiHydC(i,j) =( MAX(zero,ddRloc)*rec_dRm*dRlocM
347         &                      +MIN(zero,ddRloc)*rec_dRp*dRlocP
348         &                     )*alphaRho(i,j)
349               ELSE
350                 phiHydC(i,j) = phiHydF(i,j) + dRlocM*alphaRho(i,j)
351               ENDIF
352                 phiHydF(i,j) = phiHydC(i,j) + dRlocP*alphaRho(i,j)
353            ENDDO            ENDDO
354           ENDDO           ENDDO
355    
356  C  --  end if integr_GeoPot = ...  C  --  end if integr_GeoPot = ...
357         ENDIF         ENDIF
358    
359        ELSEIF ( buoyancyRelation .eq. 'ATMOSPHERIC' ) THEN        ELSEIF ( buoyancyRelation .EQ. 'ATMOSPHERIC' ) THEN
360  C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|  C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
361  C       This is the hydrostatic geopotential calculation for the Atmosphere  C       This is the hydrostatic geopotential calculation for the Atmosphere
362  C       The ideal gas law is used implicitly here rather than calculating  C       The ideal gas law is used implicitly here rather than calculating
363  C       the specific volume, analogous to the oceanic case.  C       the specific volume, analogous to the oceanic case.
364    
365  C       Integrate d Phi / d pi  C--     virtual potential temperature anomaly (including water vapour effect)
366            DO j=jMin,jMax
367             DO i=iMin,iMax
368              alphaRho(i,j)=maskC(i,j,k,bi,bj)
369         &             *( tFld(i,j,k,bi,bj)*(sFld(i,j,k,bi,bj)*atm_Rq+one)
370         &               -tRef(k) )
371             ENDDO
372            ENDDO
373    
374    C---    Integrate d Phi / d pi
375    
376        IF (integr_GeoPot.EQ.0) THEN         IF (integr_GeoPot.EQ.0) THEN
377  C  --  Energy Conserving Form, No hFac  --  C  --  Energy Conserving Form, accurate with Full cell topo  --
378  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
379  C             for both the "finite volume" and energy conserving methods.  C             for both the "finite volume" and energy conserving methods.
380  Ci    *NOTE* o Working with geopotential Anomaly, the geopotential boundary  C    *NOTE* o Working with geopotential Anomaly, the geopotential boundary
381  C             condition is simply Phi-prime(Ro_surf)=0.  C             condition is simply Phi-prime(Ro_surf)=0.
382  C           o convention ddPI > 0 (same as drF & drC)  C           o convention ddPI > 0 (same as drF & drC)
383  C-----------------------------------------------------------------------  C-----------------------------------------------------------------------
384          IF (K.EQ.1) THEN           IF (k.EQ.1) THEN
385            ddPIp=atm_Cp*( ((rF(K)/atm_Po)**atm_kappa)             ddPIm=atm_Cp*( ((rF( k )/atm_Po)**atm_kappa)
386       &                  -((rC(K)/atm_Po)**atm_kappa) )       &                   -((rC( k )/atm_Po)**atm_kappa) )
387            DO j=jMin,jMax           ELSE
388             DO i=iMin,iMax             ddPIm=atm_Cp*( ((rC(k-1)/atm_Po)**atm_kappa)
389  c            phiHyd(i,j,K)= phi0surf(i,j,bi,bj)+       &                   -((rC( k )/atm_Po)**atm_kappa) )*half
390               phiHyd(i,j,K)=           ENDIF
391       &          ddPIp*maskC(i,j,K,bi,bj)           IF (k.EQ.Nr) THEN
392       &               *(tFld(I,J,K,bi,bj)-tRef(K))             ddPIp=atm_Cp*( ((rC( k )/atm_Po)**atm_kappa)
393             ENDDO       &                   -((rF(k+1)/atm_Po)**atm_kappa) )
394            ENDDO           ELSE
395          ELSE             ddPIp=atm_Cp*( ((rC( k )/atm_Po)**atm_kappa)
396         &                   -((rC(k+1)/atm_Po)**atm_kappa) )*half
397             ENDIF
398  C-------- This discretization is the energy conserving form  C-------- This discretization is the energy conserving form
399            ddPI=atm_Cp*( ((rC(K-1)/atm_Po)**atm_kappa)           DO j=jMin,jMax
400       &                 -((rC( K )/atm_Po)**atm_kappa) )*0.5            DO i=iMin,iMax
401            DO j=jMin,jMax               phiHydC(i,j) = phiHydF(i,j) +ddPIm*alphaRho(i,j)
402             DO i=iMin,iMax               phiHydF(i,j) = phiHydC(i,j) +ddPIp*alphaRho(i,j)
               phiHyd(i,j,K)=phiHyd(i,j,K-1)  
      &           +ddPI*maskC(i,j,K-1,bi,bj)  
      &                *(tFld(I,J,K-1,bi,bj)-tRef(K-1))  
      &           +ddPI*maskC(i,j, K ,bi,bj)  
      &                *(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  
403            ENDDO            ENDDO
404          ENDIF           ENDDO
405  C end: Energy Conserving Form, No hFac  --  C end: Energy Conserving Form, No hFac  --
406  C-----------------------------------------------------------------------  C-----------------------------------------------------------------------
407    
408        ELSEIF (integr_GeoPot.EQ.1) THEN         ELSEIF (integr_GeoPot.EQ.1) THEN
409  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
410  C---------  C---------
411  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
412  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 :
413  C     phi_C = (phi_W_k+ phi_W_k+1)/2 ; but not accurate in Stratosphere (low p)  C     phi_C = (phi_W_k+ phi_W_k+1)/2 ; but not accurate in Stratosphere (low p)
414  C   also: if Interface_W at the middle between tracer levels, this form  C   also: if Interface_W at the middle between tracer levels, this form
415  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
416  C     non-linearity in PI(p)  C     non-linearity in PI(p)
417  C---------  C---------
418          IF (K.EQ.1) THEN             ddPIm=atm_Cp*( ((rF( k )/atm_Po)**atm_kappa)
419            ddPIp=atm_Cp*( ((rF(K)/atm_Po)**atm_kappa)       &                   -((rC( k )/atm_Po)**atm_kappa) )
420       &                  -((rC(K)/atm_Po)**atm_kappa) )             ddPIp=atm_Cp*( ((rC( k )/atm_Po)**atm_kappa)
421            DO j=jMin,jMax       &                   -((rF(k+1)/atm_Po)**atm_kappa) )
422             DO i=iMin,iMax           DO j=jMin,jMax
423  c            phiHyd(i,j,K)= phi0surf(i,j,bi,bj)+            DO i=iMin,iMax
424               phiHyd(i,j,K)=             IF (k.EQ.kSurfC(i,j,bi,bj)) THEN
425       &          ddPIp*_hFacC(I,J, K ,bi,bj)               ddRloc = Ro_surf(i,j,bi,bj)-rC(k)
426       &               *(tFld(I,J, K ,bi,bj)-tRef( K ))  #ifdef NONLIN_FRSURF
427             ENDDO               ddRloc = ddRloc + surfPhiFac*etaH(i,j,bi,bj)
428            ENDDO  #endif
429          ELSE               phiHydC(i,j) = ddRloc*recip_drF(k)*2. _d 0
430            ddPIm=atm_Cp*( ((rC(K-1)/atm_Po)**atm_kappa)       &          *ddPIm*alphaRho(i,j)
431       &                  -((rF( K )/atm_Po)**atm_kappa) )             ELSE
432            ddPIp=atm_Cp*( ((rF( K )/atm_Po)**atm_kappa)               phiHydC(i,j) = phiHydF(i,j) +ddPIm*alphaRho(i,j)
433       &                  -((rC( K )/atm_Po)**atm_kappa) )             ENDIF
434            DO j=jMin,jMax               phiHydF(i,j) = phiHydC(i,j) +ddPIp*alphaRho(i,j)
            DO i=iMin,iMax  
              phiHyd(i,j,K) = phiHyd(i,j,K-1)  
      &         +ddPIm*_hFacC(I,J,K-1,bi,bj)  
      &               *(tFld(I,J,K-1,bi,bj)-tRef(K-1))  
      &         +ddPIp*_hFacC(I,J, K ,bi,bj)  
      &               *(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  
435            ENDDO            ENDDO
436          ENDIF           ENDDO
437  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
438  C-----------------------------------------------------------------------  C-----------------------------------------------------------------------
439    
440        ELSEIF (integr_GeoPot.EQ.3) THEN         ELSEIF ( integr_GeoPot.EQ.2
441  C  --  Finite Difference Form, with hFac, Interface_W = middle  --       &     .OR. integr_GeoPot.EQ.3 ) THEN
442    C  --  Finite Difference Form, with Part-Cell Topo,
443    C       works with Interface_W  at the middle between 2.Tracer_Level
444    C        and  with Tracer_Level at the middle between 2.Interface_W.
445  C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|  C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
446  C  Finite Difference formulation consistent with Partial Cell,  C  Finite Difference formulation consistent with Partial Cell,
447  C   Valid & accurate if Interface_W at middle between tracer levels  C   Valid & accurate if Interface_W at middle between tracer levels
448  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
449  C---------  C---------
450          Kp1 = min(Nr,K+1)           IF (k.EQ.1) THEN
451          IF (K.EQ.1) THEN             ddPIm=atm_Cp*( ((rF( k )/atm_Po)**atm_kappa)
452            ratioRm=0.5*drF(K)/(rF(k)-rC(K))       &                   -((rC( k )/atm_Po)**atm_kappa) )
453            ratioRp=drF(K)*recip_drC(Kp1)           ELSE
454            ddPIm=atm_Cp*( ((rF( K )/atm_Po)**atm_kappa)             ddPIm=atm_Cp*( ((rC(k-1)/atm_Po)**atm_kappa)
455       &                  -((rC( K )/atm_Po)**atm_kappa) ) * 2. _d 0       &                   -((rC( k )/atm_Po)**atm_kappa) )*half
456            ddPIp=atm_Cp*( ((rC( K )/atm_Po)**atm_kappa)           ENDIF
457       &                  -((rC(Kp1)/atm_Po)**atm_kappa) )             IF (k.EQ.Nr) THEN
458            DO j=jMin,jMax             ddPIp=atm_Cp*( ((rC( k )/atm_Po)**atm_kappa)
459             DO i=iMin,iMax       &                   -((rF(k+1)/atm_Po)**atm_kappa) )
460  c            phiHyd(i,j,K)= phi0surf(i,j,bi,bj)+           ELSE
461               phiHyd(i,j,K)=             ddPIp=atm_Cp*( ((rC( k )/atm_Po)**atm_kappa)
462       &        ( ddPIm*max(zero,(_hFacC(i,j,K,bi,bj)-one)*ratioRm+half)       &                   -((rC(k+1)/atm_Po)**atm_kappa) )*half
463       &         +ddPIp*min(zero, _hFacC(i,j,K,bi,bj)*ratioRp     -half) )           ENDIF
464       &               *(tFld(i,j, K ,bi,bj)-tRef( K ))           rec_dRm = one/(rF(k)-rC(k))
465       &               * maskC(i,j, K ,bi,bj)           rec_dRp = one/(rC(k)-rF(k+1))
466             ENDDO           DO j=jMin,jMax
467            ENDDO            DO i=iMin,iMax
468          ELSE             IF (k.EQ.kSurfC(i,j,bi,bj)) THEN
469            ratioRm=drF(K)*recip_drC(K)               ddRloc = Ro_surf(i,j,bi,bj)-rC(k)
470            ratioRp=drF(K)*recip_drC(Kp1)  #ifdef NONLIN_FRSURF
471            ddPIm=atm_Cp*( ((rC(K-1)/atm_Po)**atm_kappa)               ddRloc = ddRloc + surfPhiFac*etaH(i,j,bi,bj)
472       &                  -((rC( K )/atm_Po)**atm_kappa) )  #endif
473            ddPIp=atm_Cp*( ((rC( K )/atm_Po)**atm_kappa)               phiHydC(i,j) =( MAX(zero,ddRloc)*rec_dRm*ddPIm
474       &                  -((rC(Kp1)/atm_Po)**atm_kappa) )       &                      +MIN(zero,ddRloc)*rec_dRp*ddPIp )
475            DO j=jMin,jMax       &                    *alphaRho(i,j)
476             DO i=iMin,iMax             ELSE
477               phiHyd(i,j,K) = phiHyd(i,j,K-1)               phiHydC(i,j) = phiHydF(i,j) +ddPIm*alphaRho(i,j)
478       &        + ddPIm*0.5             ENDIF
479       &               *(tFld(i,j,K-1,bi,bj)-tRef(K-1))               phiHydF(i,j) = phiHydC(i,j) +ddPIp*alphaRho(i,j)
      &               * maskC(i,j,K-1,bi,bj)  
      &        +(ddPIm*max(zero,(_hFacC(i,j,K,bi,bj)-one)*ratioRm+half)  
      &         +ddPIp*min(zero, _hFacC(i,j,K,bi,bj)*ratioRp     -half) )  
      &               *(tFld(i,j, K ,bi,bj)-tRef( K ))  
      &               * maskC(i,j, K ,bi,bj)  
            ENDDO  
480            ENDDO            ENDDO
481          ENDIF           ENDDO
482  C end: Finite Difference Form, with hFac, Interface_W = middle  --  C end: Finite Difference Form, with Part-Cell Topo
483  C-----------------------------------------------------------------------  C-----------------------------------------------------------------------
484    
485        ELSE         ELSE
486          STOP 'CALC_PHI_HYD: Bad integr_GeoPot option !'           STOP 'CALC_PHI_HYD: Bad integr_GeoPot option !'
487        ENDIF         ENDIF
488    
489  C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|  C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
490        ELSE        ELSE
491          STOP 'CALC_PHI_HYD: Bad value of buoyancyRelation !'          STOP 'CALC_PHI_HYD: Bad value of buoyancyRelation !'
492        ENDIF        ENDIF
493    
494        IF (momPressureForcing) THEN  C---   Diagnose Phi at boundary r=R_low :
495          iMnLoc = MAX(1-Olx+1,iMin)  C       = Ocean bottom pressure (Ocean, Z-coord.)
496          jMnLoc = MAX(1-Oly+1,jMin)  C       = Sea-surface height    (Ocean, P-coord.)
497    C       = Top atmosphere height (Atmos, P-coord.)
498          IF (useDiagPhiRlow) THEN
499            CALL DIAGS_PHI_RLOW(
500         I                      k, bi, bj, iMin,iMax, jMin,jMax,
501         I                      phiHydF, phiHydC, alphaRho, tFld, sFld,
502         I                      myTime, myIter, myThid)
503          ENDIF
504    
505    C---   Diagnose Full Hydrostatic Potential at cell center level
506            CALL DIAGS_PHI_HYD(
507         I                      k, bi, bj, iMin,iMax, jMin,jMax,
508         I                      phiHydC,
509         I                      myTime, myIter, myThid)
510    
511          IF (momPressureForcing) THEN
512          CALL CALC_GRAD_PHI_HYD(          CALL CALC_GRAD_PHI_HYD(
513       I                         k, bi, bj, iMnLoc,iMax, jMnLoc,jMax,       I                         k, bi, bj, iMin,iMax, jMin,jMax,
514       I                         phiHyd, alphaRho, tFld, sFld,       I                         phiHydC, alphaRho, tFld, sFld,
515       O                         dPhiHydX, dPhiHydY,       O                         dPhiHydX, dPhiHydY,
516       I                         myTime, myIter, myThid)         I                         myTime, myIter, myThid)
517        ENDIF        ENDIF
518    
519  #endif /* INCLUDE_PHIHYD_CALCULATION_CODE */  #endif /* INCLUDE_PHIHYD_CALCULATION_CODE */

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

  ViewVC Help
Powered by ViewVC 1.1.22