/[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.16 by cnh, Wed Sep 26 18:09:14 2001 UTC revision 1.32 by jmc, Mon Jan 3 03:04:37 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  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                         theta, salt,       I                         tFld, sFld,
13       U                         phiHyd,       U                         phiHydF,
14       I                         myThid)       O                         phiHydC, dPhiHydX, dPhiHydY,
15         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     |   theta,salt    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 49  C     == Global variables == Line 46  C     == Global variables ==
46  #include "tamc.h"  #include "tamc.h"
47  #include "tamc_keys.h"  #include "tamc_keys.h"
48  #endif /* ALLOW_AUTODIFF_TAMC */  #endif /* ALLOW_AUTODIFF_TAMC */
49    #include "SURFACE.h"
50    #include "DYNVARS.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        _RL theta(1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr,nSx,nSy)  C     iMin,iMax,jMin,jMax :: computational domain
56        _RL salt(1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr,nSx,nSy)  C     tFld       :: potential temperature
57        _RL phiHyd(1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr)  C     sFld       :: salinity
58        INTEGER myThid  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)
67          _RL sFld(1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr,nSx,nSy)
68    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)
72          _RL dPhiHydY(1-Olx:sNx+Olx,1-Oly:sNy+Oly)
73          _RL myTime
74          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        _RL dRlocM,dRlocP, ddRloc, locAlpha
84        _RL ddPI, ddPIm, ddPIp, ratioRp, ratioRm        _RL ddPIm, ddPIp, rec_dRm, rec_dRp
85          _RL surfPhiFac
86          INTEGER iMnLoc,jMnLoc
87          PARAMETER ( zero= 0. _d 0 , one= 1. _d 0 , half= .5 _d 0 )
88          LOGICAL useDiagPhiRlow, addSurfPhiAnom
89  CEOP  CEOP
90          useDiagPhiRlow = .TRUE.
91        zero = 0. _d 0        addSurfPhiAnom = select_rStar.EQ.0 .AND. nonlinFreeSurf.GT.3
92        one  = 1. _d 0        surfPhiFac = 0.
93        half = .5 _d 0        IF (addSurfPhiAnom) surfPhiFac = 1.
94    
95  C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|  C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
96  C  Atmosphere:    C  Atmosphere:  
97  C Integr_GeoPot => select one option for the integration of the Geopotential:  C integr_GeoPot => select one option for the integration of the Geopotential:
98  C   = 0 : Energy Conserving Form, No hFac ;  C   = 0 : Energy Conserving Form, accurate with Topo full cell;
99  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;
100  C   =2,3: Finite Difference Form, with hFac, linear in P between 2 Tracer levels  C   =2,3: Finite Difference Form, with Part-Cell,
101  C     2 : case Tracer level at the middle of InterFace_W;  C         linear in P between 2 Tracer levels.
102  C     3 : case InterFace_W  at the middle of Tracer levels;  C       can handle both cases: Tracer lev at the middle of InterFace_W
103    C                          and InterFace_W at the middle of Tracer lev;
104  C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|  C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
105    
106  #ifdef ALLOW_AUTODIFF_TAMC  #ifdef ALLOW_AUTODIFF_TAMC
# Line 100  C---+----1----+----2----+----3----+----4 Line 120  C---+----1----+----2----+----3----+----4
120       &                      + act4*max1*max2*max3       &                      + act4*max1*max2*max3
121  #endif /* ALLOW_AUTODIFF_TAMC */  #endif /* ALLOW_AUTODIFF_TAMC */
122    
123        IF ( buoyancyRelation .eq. 'OCEANIC' ) THEN  C--   Initialize phiHydF to zero :
124    C     note: atmospheric_loading or Phi_topo anomaly are incorporated
125    C           later in S/R calc_grad_phi_hyd
126          IF (k.EQ.1) THEN
127            DO j=1-Oly,sNy+Oly
128             DO i=1-Olx,sNx+Olx
129               phiHydF(i,j) = 0.
130             ENDDO
131            ENDDO
132          ENDIF
133    
134    C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
135          IF ( buoyancyRelation .EQ. 'OCEANIC' ) THEN
136  C       This is the hydrostatic pressure calculation for the Ocean  C       This is the hydrostatic pressure calculation for the Ocean
137  C       which uses the FIND_RHO() routine to calculate density  C       which uses the FIND_RHO() routine to calculate density
138  C       before integrating g*rho over the current layer/interface  C       before integrating g*rho over the current layer/interface
139    #ifdef      ALLOW_AUTODIFF_TAMC
140    CADJ GENERAL
141    #endif      /* ALLOW_AUTODIFF_TAMC */
142    
143    C---    Calculate density
144    #ifdef ALLOW_AUTODIFF_TAMC
145            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( bi, bj, iMin, iMax, jMin, jMax, k, k,
150         &                 tFld, sFld,
151         &                 alphaRho, myThid)
152    
153          dRloc=drC(k)  #ifdef ALLOW_DIAGNOSTICS
154          IF (k.EQ.1) dRloc=drF(1)          IF ( useDiagnostics )
155          IF (k.EQ.Nr) THEN       &   CALL DIAGNOSTICS_FILL(alphaRho,'RHOAnoma',k,1,2,bi,bj,myThid)
156            dRlocKp1=0.  #endif
157          ELSE  
158            dRlocKp1=drC(k+1)  C Quasi-hydrostatic terms are added in as if they modify the buoyancy
159            IF (quasiHydrostatic) THEN
160             CALL QUASIHYDROSTATICTERMS(bi,bj,k,alphaRho,myThid)
161          ENDIF          ENDIF
162    
163  C--     If this is the top layer we impose the boundary condition  #ifdef NONLIN_FRSURF
164  C       P(z=eta) = P(atmospheric_loading)          IF (k.EQ.1 .AND. addSurfPhiAnom) THEN
         IF (k.EQ.1) THEN  
165            DO j=jMin,jMax            DO j=jMin,jMax
166              DO i=iMin,iMax              DO i=iMin,iMax
167  C             *NOTE* The loading should go here but has not been implemented yet                phiHydF(i,j) = surfPhiFac*etaH(i,j,bi,bj)
168                phiHyd(i,j,k)=0.       &                      *gravity*alphaRho(i,j)*recip_rhoConst
169              ENDDO              ENDDO
170            ENDDO            ENDDO
171          ENDIF          ENDIF
172    #endif /* NONLIN_FRSURF */
173    
174    C----  Hydrostatic pressure at cell centers
175    
176  C       Calculate density         IF (integr_GeoPot.EQ.1) THEN
177    C  --  Finite Volume Form
178    
179             DO j=jMin,jMax
180              DO i=iMin,iMax
181    
182    C---------- This discretization is the "finite volume" form
183    C           which has not been used to date since it does not
184    C           conserve KE+PE exactly even though it is more natural
185    C
186               phiHydC(i,j)=phiHydF(i,j)
187         &       + half*drF(k)*gravity*alphaRho(i,j)*recip_rhoConst
188               phiHydF(i,j)=phiHydF(i,j)
189         &            + drF(k)*gravity*alphaRho(i,j)*recip_rhoConst
190              ENDDO
191             ENDDO
192    
193           ELSE
194    C  --  Finite Difference Form
195    
196             dRlocM=half*drC(k)
197             IF (k.EQ.1) dRlocM=rF(k)-rC(k)
198             IF (k.EQ.Nr) THEN
199               dRlocP=rC(k)-rF(k+1)
200             ELSE
201               dRlocP=half*drC(k+1)
202             ENDIF
203    
204             DO j=jMin,jMax
205              DO i=iMin,iMax
206    
207    C---------- This discretization is the "energy conserving" form
208    C           which has been used since at least Adcroft et al., MWR 1997
209    C
210                phiHydC(i,j)=phiHydF(i,j)
211         &        +dRlocM*gravity*alphaRho(i,j)*recip_rhoConst
212                phiHydF(i,j)=phiHydC(i,j)
213         &        +dRlocP*gravity*alphaRho(i,j)*recip_rhoConst
214              ENDDO
215             ENDDO
216    
217    C  --  end if integr_GeoPot = ...
218           ENDIF
219            
220    C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
221          ELSEIF ( buoyancyRelation .EQ. 'OCEANICP' ) THEN
222    C       This is the hydrostatic pressure calculation for the Ocean
223    C       which uses the FIND_RHO() routine to calculate density
224    C       before integrating (1/rho)'*dp over the current layer/interface
225    #ifdef      ALLOW_AUTODIFF_TAMC
226    CADJ GENERAL
227    #endif      /* ALLOW_AUTODIFF_TAMC */
228    
229    C--     Calculate density
230  #ifdef ALLOW_AUTODIFF_TAMC  #ifdef ALLOW_AUTODIFF_TAMC
231              kkey = (ikey-1)*Nr + k              kkey = (ikey-1)*Nr + k
232  CADJ STORE theta(:,:,k,bi,bj) = comlev1_bibj_k, key=kkey, byte=isbyte  CADJ STORE tFld (:,:,k,bi,bj) = comlev1_bibj_k, key=kkey, byte=isbyte
233  CADJ STORE salt (:,:,k,bi,bj) = comlev1_bibj_k, key=kkey, byte=isbyte  CADJ STORE sFld (:,:,k,bi,bj) = comlev1_bibj_k, key=kkey, byte=isbyte
234  #endif /* ALLOW_AUTODIFF_TAMC */  #endif /* ALLOW_AUTODIFF_TAMC */
235          CALL FIND_RHO( bi, bj, iMin, iMax, jMin, jMax, k, k, eosType,          CALL FIND_RHO( bi, bj, iMin, iMax, jMin, jMax, k, k,
236       &                 theta, salt,       &                 tFld, sFld,
237       &                 alphaRho, myThid)       &                 alphaRho, myThid)
238    #ifdef ALLOW_AUTODIFF_TAMC
239    CADJ STORE alphaRho (:,:) = comlev1_bibj_k, key=kkey, byte=isbyte
240    #endif /* ALLOW_AUTODIFF_TAMC */
241    
242    #ifdef ALLOW_DIAGNOSTICS
243            IF ( useDiagnostics )
244         &   CALL DIAGNOSTICS_FILL(alphaRho,'RHOAnoma',k,1,2,bi,bj,myThid)
245    #endif
246    
247  C       Hydrostatic pressure at cell centers  C--     Calculate specific volume anomaly : alpha' = 1/rho - alpha_Cst
248          DO j=jMin,jMax          DO j=jMin,jMax
249            DO i=iMin,iMax            DO i=iMin,iMax
250  #ifdef      ALLOW_AUTODIFF_TAMC              locAlpha=alphaRho(i,j)+rhoConst
251  c           Patrick, is this directive correct or even necessary in              alphaRho(i,j)=maskC(i,j,k,bi,bj)*
252  c           this new code?       &              (one/locAlpha - recip_rhoConst)
253  c           Yes, because of phiHyd(i,j,k+1)=phiHyd(i,j,k)+...            ENDDO
254  c           within the k-loop.          ENDDO
255  CADJ GENERAL  
256  #endif      /* ALLOW_AUTODIFF_TAMC */  C----  Hydrostatic pressure at cell centers
257    
258           IF (integr_GeoPot.EQ.1) THEN
259    C  --  Finite Volume Form
260    
261             DO j=jMin,jMax
262              DO i=iMin,iMax
263    
264  C---------- This discretization is the "finite volume" form  C---------- This discretization is the "finite volume" form
265  C           which has not been used to date since it does not  C           which has not been used to date since it does not
266  C           conserve KE+PE exactly even though it is more natural  C           conserve KE+PE exactly even though it is more natural
267  C  C
268  c           IF (k.LT.Nr) phiHyd(i,j,k+1)=phiHyd(i,j,k)+             IF (k.EQ.ksurfC(i,j,bi,bj)) THEN
269  c    &              drF(K)*gravity*alphaRho(i,j)*recip_rhoConst               ddRloc = Ro_surf(i,j,bi,bj)-rC(k)
270  c           phiHyd(i,j,k)=phiHyd(i,j,k)+  #ifdef NONLIN_FRSURF
271  c    &          0.5*drF(K)*gravity*alphaRho(i,j)*recip_rhoConst               ddRloc = ddRloc + surfPhiFac*etaH(i,j,bi,bj)
272  C-----------------------------------------------------------------------  #endif
273                 phiHydC(i,j) = ddRloc*alphaRho(i,j)
274    c--to reproduce results of c48d_post: uncomment those 4+1 lines
275    c            phiHydC(i,j)=phiHydF(i,j)
276    c    &          +(hFacC(i,j,k,bi,bj)-half)*drF(k)*alphaRho(i,j)
277    c            phiHydF(i,j)=phiHydF(i,j)
278    c    &          + hFacC(i,j,k,bi,bj)*drF(k)*alphaRho(i,j)
279               ELSE
280                 phiHydC(i,j) = phiHydF(i,j) + half*drF(k)*alphaRho(i,j)
281    c            phiHydF(i,j) = phiHydF(i,j) +      drF(k)*alphaRho(i,j)
282               ENDIF
283    c-- and comment this last one:
284                 phiHydF(i,j) = phiHydC(i,j) + half*drF(k)*alphaRho(i,j)
285    c-----
286              ENDDO
287             ENDDO
288    
289           ELSE
290    C  --  Finite Difference Form, with Part-Cell Bathy
291    
292             dRlocM=half*drC(k)
293             IF (k.EQ.1) dRlocM=rF(k)-rC(k)
294             IF (k.EQ.Nr) THEN
295               dRlocP=rC(k)-rF(k+1)
296             ELSE
297               dRlocP=half*drC(k+1)
298             ENDIF
299             rec_dRm = one/(rF(k)-rC(k))
300             rec_dRp = one/(rC(k)-rF(k+1))
301    
302             DO j=jMin,jMax
303              DO i=iMin,iMax
304    
305  C---------- This discretization is the "energy conserving" form  C---------- This discretization is the "energy conserving" form
306  C           which has been used since at least Adcroft et al., MWR 1997  
307  C             IF (k.EQ.ksurfC(i,j,bi,bj)) THEN
308              phiHyd(i,j,k)=phiHyd(i,j,k)+               ddRloc = Ro_surf(i,j,bi,bj)-rC(k)
309       &          0.5*dRloc*gravity*alphaRho(i,j)*recip_rhoConst  #ifdef NONLIN_FRSURF
310              IF (k.LT.Nr) phiHyd(i,j,k+1)=phiHyd(i,j,k)+               ddRloc = ddRloc + surfPhiFac*etaH(i,j,bi,bj)
311       &          0.5*dRlocKp1*gravity*alphaRho(i,j)*recip_rhoConst  #endif
312  C-----------------------------------------------------------------------               phiHydC(i,j) =( MAX(zero,ddRloc)*rec_dRm*dRlocM
313         &                      +MIN(zero,ddRloc)*rec_dRp*dRlocP
314         &                     )*alphaRho(i,j)
315               ELSE
316                 phiHydC(i,j) = phiHydF(i,j) + dRlocM*alphaRho(i,j)
317               ENDIF
318                 phiHydF(i,j) = phiHydC(i,j) + dRlocP*alphaRho(i,j)
319            ENDDO            ENDDO
320          ENDDO           ENDDO
           
321    
322    C  --  end if integr_GeoPot = ...
323           ENDIF
324    
325        ELSEIF ( buoyancyRelation .eq. 'ATMOSPHERIC' ) THEN        ELSEIF ( buoyancyRelation .EQ. 'ATMOSPHERIC' ) THEN
326  C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|  C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
327  C       This is the hydrostatic geopotential calculation for the Atmosphere  C       This is the hydrostatic geopotential calculation for the Atmosphere
328  C       The ideal gas law is used implicitly here rather than calculating  C       The ideal gas law is used implicitly here rather than calculating
329  C       the specific volume, analogous to the oceanic case.  C       the specific volume, analogous to the oceanic case.
330    
331  C       Integrate d Phi / d pi  C--     virtual potential temperature anomaly (including water vapour effect)
332            DO j=jMin,jMax
333             DO i=iMin,iMax
334              alphaRho(i,j)=maskC(i,j,k,bi,bj)
335         &             *( tFld(i,j,k,bi,bj)*(sFld(i,j,k,bi,bj)*atm_Rq+one)
336         &               -tRef(k) )
337             ENDDO
338            ENDDO
339    
340    C---    Integrate d Phi / d pi
341    
342        IF (Integr_GeoPot.EQ.0) THEN         IF (integr_GeoPot.EQ.0) THEN
343  C  --  Energy Conserving Form, No hFac  --  C  --  Energy Conserving Form, accurate with Full cell topo  --
344  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
345  C             for both the "finite volume" and energy conserving methods.  C             for both the "finite volume" and energy conserving methods.
346  C    *NOTE* o Working with geopotential Anomaly, the geopotential boundary  C    *NOTE* o Working with geopotential Anomaly, the geopotential boundary
347  C             condition is simply Phi'(Ro_surf)=0.  C             condition is simply Phi-prime(Ro_surf)=0.
348  C           o convention ddPI > 0 (same as drF & drC)  C           o convention ddPI > 0 (same as drF & drC)
349  C-----------------------------------------------------------------------  C-----------------------------------------------------------------------
350          IF (K.EQ.1) THEN           IF (k.EQ.1) THEN
351            ddPIp=atm_cp*( ((rF(K)/atm_po)**atm_kappa)             ddPIm=atm_Cp*( ((rF( k )/atm_Po)**atm_kappa)
352       &                  -((rC(K)/atm_po)**atm_kappa) )       &                   -((rC( k )/atm_Po)**atm_kappa) )
353            DO j=jMin,jMax           ELSE
354             DO i=iMin,iMax             ddPIm=atm_Cp*( ((rC(k-1)/atm_Po)**atm_kappa)
355               phiHyd(i,j,K)=       &                   -((rC( k )/atm_Po)**atm_kappa) )*half
356       &          ddPIp*maskC(i,j,K,bi,bj)           ENDIF
357       &               *(theta(I,J,K,bi,bj)-tRef(K))           IF (k.EQ.Nr) THEN
358             ENDDO             ddPIp=atm_Cp*( ((rC( k )/atm_Po)**atm_kappa)
359            ENDDO       &                   -((rF(k+1)/atm_Po)**atm_kappa) )
360          ELSE           ELSE
361               ddPIp=atm_Cp*( ((rC( k )/atm_Po)**atm_kappa)
362         &                   -((rC(k+1)/atm_Po)**atm_kappa) )*half
363             ENDIF
364  C-------- This discretization is the energy conserving form  C-------- This discretization is the energy conserving form
365            ddPI=atm_cp*( ((rC(K-1)/atm_po)**atm_kappa)           DO j=jMin,jMax
366       &                 -((rC( K )/atm_po)**atm_kappa) )*0.5            DO i=iMin,iMax
367            DO j=jMin,jMax               phiHydC(i,j) = phiHydF(i,j) +ddPIm*alphaRho(i,j)
368             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)  
      &                *(theta(I,J,K-1,bi,bj)-tRef(K-1))  
      &           +ddPI*maskC(i,j, K ,bi,bj)  
      &                *(theta(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 &      (theta(I,J,K-1,bi,bj)+theta(I,J,K,bi,bj)-2.*tRef(K))  
            ENDDO  
369            ENDDO            ENDDO
370          ENDIF           ENDDO
371  C end: Energy Conserving Form, No hFac  --  C end: Energy Conserving Form, No hFac  --
372  C-----------------------------------------------------------------------  C-----------------------------------------------------------------------
373    
374        ELSEIF (Integr_GeoPot.EQ.1) THEN         ELSEIF (integr_GeoPot.EQ.1) THEN
375  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
376  C---------  C---------
377  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
378  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 224  C   also: if Interface_W at the middle b Line 381  C   also: if Interface_W at the middle b
381  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
382  C     non-linearity in PI(p)  C     non-linearity in PI(p)
383  C---------  C---------
384          IF (K.EQ.1) THEN             ddPIm=atm_Cp*( ((rF( k )/atm_Po)**atm_kappa)
385            ddPIp=atm_cp*( ((rF(K)/atm_po)**atm_kappa)       &                   -((rC( k )/atm_Po)**atm_kappa) )
386       &                  -((rC(K)/atm_po)**atm_kappa) )             ddPIp=atm_Cp*( ((rC( k )/atm_Po)**atm_kappa)
387            DO j=jMin,jMax       &                   -((rF(k+1)/atm_Po)**atm_kappa) )
388             DO i=iMin,iMax           DO j=jMin,jMax
389               phiHyd(i,j,K) =            DO i=iMin,iMax
390       &          ddPIp*hFacC(I,J, K ,bi,bj)             IF (k.EQ.ksurfC(i,j,bi,bj)) THEN
391       &               *(theta(I,J, K ,bi,bj)-tRef( K ))               ddRloc = Ro_surf(i,j,bi,bj)-rC(k)
392             ENDDO  #ifdef NONLIN_FRSURF
393            ENDDO               ddRloc = ddRloc + surfPhiFac*etaH(i,j,bi,bj)
394          ELSE  #endif
395            ddPIm=atm_cp*( ((rC(K-1)/atm_po)**atm_kappa)               phiHydC(i,j) = ddRloc*recip_drF(k)*2. _d 0
396       &                  -((rF( K )/atm_po)**atm_kappa) )       &          *ddPIm*alphaRho(i,j)
397            ddPIp=atm_cp*( ((rF( K )/atm_po)**atm_kappa)             ELSE
398       &                  -((rC( K )/atm_po)**atm_kappa) )               phiHydC(i,j) = phiHydF(i,j) +ddPIm*alphaRho(i,j)
399            DO j=jMin,jMax             ENDIF
400             DO i=iMin,iMax               phiHydF(i,j) = phiHydC(i,j) +ddPIp*alphaRho(i,j)
              phiHyd(i,j,K) = phiHyd(i,j,K-1)  
      &         +ddPIm*hFacC(I,J,K-1,bi,bj)  
      &               *(theta(I,J,K-1,bi,bj)-tRef(K-1))  
      &         +ddPIp*hFacC(I,J, K ,bi,bj)  
      &               *(theta(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  
              phiHyd(i,j,K) =  
      &        ( ddPIm*max(zero, hFacC(i,j,K,bi,bj)-half)  
      &         +ddPIp*min(zero, hFacC(i,j,K,bi,bj)-half) )  
      &               *(theta(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  
      &               *(theta(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) )  
      &               *(theta(i,j, K ,bi,bj)-tRef( K ))  
      &               * maskC(i,j, K ,bi,bj)  
            ENDDO  
401            ENDDO            ENDDO
402          ENDIF           ENDDO
403  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
404  C-----------------------------------------------------------------------  C-----------------------------------------------------------------------
405    
406        ELSEIF (Integr_GeoPot.EQ.3) THEN         ELSEIF ( integr_GeoPot.EQ.2
407  C  --  Finite Difference Form, with hFac, Interface_W = middle  --       &     .OR. integr_GeoPot.EQ.3 ) THEN
408    C  --  Finite Difference Form, with Part-Cell Topo,
409    C       works with Interface_W  at the middle between 2.Tracer_Level
410    C        and  with Tracer_Level at the middle between 2.Interface_W.
411  C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|  C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
412  C  Finite Difference formulation consistent with Partial Cell,  C  Finite Difference formulation consistent with Partial Cell,
413  C   Valid & accurate if Interface_W at middle between tracer levels  C   Valid & accurate if Interface_W at middle between tracer levels
414  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
415  C---------  C---------
416          Kp1 = min(Nr,K+1)           IF (k.EQ.1) THEN
417          IF (K.EQ.1) THEN             ddPIm=atm_Cp*( ((rF( k )/atm_Po)**atm_kappa)
418            ratioRm=0.5*drF(K)/(rF(k)-rC(K))       &                   -((rC( k )/atm_Po)**atm_kappa) )
419            ratioRp=drF(K)*recip_drC(Kp1)           ELSE
420            ddPIm=atm_cp*( ((rF( K )/atm_po)**atm_kappa)             ddPIm=atm_Cp*( ((rC(k-1)/atm_Po)**atm_kappa)
421       &                  -((rC( K )/atm_po)**atm_kappa) ) * 2. _d 0       &                   -((rC( k )/atm_Po)**atm_kappa) )*half
422            ddPIp=atm_cp*( ((rC( K )/atm_po)**atm_kappa)           ENDIF
423       &                  -((rC(Kp1)/atm_po)**atm_kappa) )             IF (k.EQ.Nr) THEN
424            DO j=jMin,jMax             ddPIp=atm_Cp*( ((rC( k )/atm_Po)**atm_kappa)
425             DO i=iMin,iMax       &                   -((rF(k+1)/atm_Po)**atm_kappa) )
426               phiHyd(i,j,K) =           ELSE
427       &        ( ddPIm*max(zero,(hFacC(i,j,K,bi,bj)-one)*ratioRm+half)             ddPIp=atm_Cp*( ((rC( k )/atm_Po)**atm_kappa)
428       &         +ddPIp*min(zero, hFacC(i,j,K,bi,bj)*ratioRp     -half) )       &                   -((rC(k+1)/atm_Po)**atm_kappa) )*half
429       &               *(theta(i,j, K ,bi,bj)-tRef( K ))           ENDIF
430       &               * maskC(i,j, K ,bi,bj)           rec_dRm = one/(rF(k)-rC(k))
431             ENDDO           rec_dRp = one/(rC(k)-rF(k+1))
432            ENDDO           DO j=jMin,jMax
433          ELSE            DO i=iMin,iMax
434            ratioRm=drF(K)*recip_drC(K)             IF (k.EQ.ksurfC(i,j,bi,bj)) THEN
435            ratioRp=drF(K)*recip_drC(Kp1)               ddRloc = Ro_surf(i,j,bi,bj)-rC(k)
436            ddPIm=atm_cp*( ((rC(K-1)/atm_po)**atm_kappa)  #ifdef NONLIN_FRSURF
437       &                  -((rC( K )/atm_po)**atm_kappa) )               ddRloc = ddRloc + surfPhiFac*etaH(i,j,bi,bj)
438            ddPIp=atm_cp*( ((rC( K )/atm_po)**atm_kappa)  #endif
439       &                  -((rC(Kp1)/atm_po)**atm_kappa) )               phiHydC(i,j) =( MAX(zero,ddRloc)*rec_dRm*ddPIm
440            DO j=jMin,jMax       &                      +MIN(zero,ddRloc)*rec_dRp*ddPIp )
441             DO i=iMin,iMax       &                    *alphaRho(i,j)
442               phiHyd(i,j,K) = phiHyd(i,j,K-1)             ELSE
443       &        + ddPIm*0.5               phiHydC(i,j) = phiHydF(i,j) +ddPIm*alphaRho(i,j)
444       &               *(theta(i,j,K-1,bi,bj)-tRef(K-1))             ENDIF
445       &               * maskC(i,j,K-1,bi,bj)               phiHydF(i,j) = phiHydC(i,j) +ddPIp*alphaRho(i,j)
      &        +(ddPIm*max(zero,(hFacC(i,j,K,bi,bj)-one)*ratioRm+half)  
      &         +ddPIp*min(zero, hFacC(i,j,K,bi,bj)*ratioRp     -half) )  
      &               *(theta(i,j, K ,bi,bj)-tRef( K ))  
      &               * maskC(i,j, K ,bi,bj)  
            ENDDO  
446            ENDDO            ENDDO
447          ENDIF           ENDDO
448  C end: Finite Difference Form, with hFac, Interface_W = middle  --  C end: Finite Difference Form, with Part-Cell Topo
449  C-----------------------------------------------------------------------  C-----------------------------------------------------------------------
450    
451        ELSE         ELSE
452          STOP 'CALC_PHI_HYD: Bad Integr_GeoPot option !'           STOP 'CALC_PHI_HYD: Bad integr_GeoPot option !'
453        ENDIF         ENDIF
454    
455  C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|  C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
456        ELSE        ELSE
457          STOP 'CALC_PHI_HYD: We should never reach this point!'          STOP 'CALC_PHI_HYD: Bad value of buoyancyRelation !'
458          ENDIF
459    
460    C---   Diagnose Phi at boundary r=R_low :
461    C       = Ocean bottom pressure (Ocean, Z-coord.)
462    C       = Sea-surface height    (Ocean, P-coord.)
463    C       = Top atmosphere height (Atmos, P-coord.)
464          IF (useDiagPhiRlow) THEN
465            CALL DIAGS_PHI_RLOW(
466         I                      k, bi, bj, iMin,iMax, jMin,jMax,
467         I                      phiHydF, phiHydC, alphaRho, tFld, sFld,
468         I                      myTime, myIter, myThid)  
469          ENDIF
470    
471    C---   Diagnose Full Hydrostatic Potential at cell center level
472            CALL DIAGS_PHI_HYD(
473         I                      k, bi, bj, iMin,iMax, jMin,jMax,
474         I                      phiHydC,
475         I                      myTime, myIter, myThid)
476    
477          IF (momPressureForcing) THEN
478            iMnLoc = MAX(1-Olx+1,iMin)
479            jMnLoc = MAX(1-Oly+1,jMin)
480            CALL CALC_GRAD_PHI_HYD(
481         I                         k, bi, bj, iMnLoc,iMax, jMnLoc,jMax,
482         I                         phiHydC, alphaRho, tFld, sFld,
483         O                         dPhiHydX, dPhiHydY,
484         I                         myTime, myIter, myThid)  
485        ENDIF        ENDIF
486    
487  #endif /* INCLUDE_PHIHYD_CALCULATION_CODE */  #endif /* INCLUDE_PHIHYD_CALCULATION_CODE */

Legend:
Removed from v.1.16  
changed lines
  Added in v.1.32

  ViewVC Help
Powered by ViewVC 1.1.22