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

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

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

revision 1.37 by mlosch, Tue May 13 13:30:05 2003 UTC revision 1.69 by mlosch, Mon Nov 23 16:15:54 2009 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
# Line 10  C     !INTERFACE: Line 11  C     !INTERFACE:
11    
12  C     !DESCRIPTION: \bv  C     !DESCRIPTION: \bv
13  C     *==========================================================*  C     *==========================================================*
14  C     | SUBROUTINE SOLVE_FOR_PRESSURE                              C     | SUBROUTINE SOLVE_FOR_PRESSURE
15  C     | o Controls inversion of two and/or three-dimensional        C     | o Controls inversion of two and/or three-dimensional
16  C     |   elliptic problems for the pressure field.                C     |   elliptic problems for the pressure field.
17  C     *==========================================================*  C     *==========================================================*
18  C     \ev  C     \ev
19    
# Line 22  C     == Global variables Line 23  C     == Global variables
23  #include "SIZE.h"  #include "SIZE.h"
24  #include "EEPARAMS.h"  #include "EEPARAMS.h"
25  #include "PARAMS.h"  #include "PARAMS.h"
 #include "DYNVARS.h"  
26  #include "GRID.h"  #include "GRID.h"
27  #include "SURFACE.h"  #include "SURFACE.h"
28  #include "FFIELDS.h"  #include "FFIELDS.h"
29    #include "DYNVARS.h"
30    #include "SOLVE_FOR_PRESSURE.h"
31  #ifdef ALLOW_NONHYDROSTATIC  #ifdef ALLOW_NONHYDROSTATIC
32  #include "SOLVE_FOR_PRESSURE3D.h"  #include "SOLVE_FOR_PRESSURE3D.h"
33  #include "GW.h"  #include "NH_VARS.h"
34    #endif
35    #ifdef ALLOW_CD_CODE
36    #include "CD_CODE_VARS.h"
37  #endif  #endif
38  #ifdef ALLOW_OBCS  #ifdef ALLOW_OBCS
39  #include "OBCS.h"  #include "OBCS.h"
40  #endif  #endif
 #include "SOLVE_FOR_PRESSURE.h"  
41    
42  C     === Functions ====  C     === Functions ====
43        LOGICAL  DIFFERENT_MULTIPLE        LOGICAL  DIFFERENT_MULTIPLE
# Line 41  C     === Functions ==== Line 45  C     === Functions ====
45    
46  C     !INPUT/OUTPUT PARAMETERS:  C     !INPUT/OUTPUT PARAMETERS:
47  C     == Routine arguments ==  C     == Routine arguments ==
48  C     myTime - Current time in simulation  C     myTime :: Current time in simulation
49  C     myIter - Current iteration number in simulation  C     myIter :: Current iteration number in simulation
50  C     myThid - Thread number for this instance of SOLVE_FOR_PRESSURE  C     myThid :: Thread number for this instance of SOLVE_FOR_PRESSURE
51        _RL myTime        _RL myTime
52        INTEGER myIter        INTEGER myIter
53        INTEGER myThid        INTEGER myThid
# Line 51  C     myThid - Thread number for this in Line 55  C     myThid - Thread number for this in
55  C     !LOCAL VARIABLES:  C     !LOCAL VARIABLES:
56  C     == Local variables ==  C     == Local variables ==
57        INTEGER i,j,k,bi,bj        INTEGER i,j,k,bi,bj
       _RS uf(1-Olx:sNx+Olx,1-Oly:sNy+Oly)  
       _RS vf(1-Olx:sNx+Olx,1-Oly:sNy+Oly)  
58        _RL firstResidual,lastResidual        _RL firstResidual,lastResidual
59        _RL tmpFac        _RL tmpFac
60        INTEGER numIters        _RL sumEmP, tileEmP(nSx,nSy)
61          LOGICAL putPmEinXvector
62          INTEGER numIters, ks
63          CHARACTER*10 sufx
64        CHARACTER*(MAX_LEN_MBUF) msgBuf        CHARACTER*(MAX_LEN_MBUF) msgBuf
65    #ifdef ALLOW_NONHYDROSTATIC
66          INTEGER kp1
67          _RL     wFacKm, wFacKp
68          LOGICAL zeroPsNH
69          _RL     uf(1-Olx:sNx+Olx,1-Oly:sNy+Oly)
70          _RL     vf(1-Olx:sNx+Olx,1-Oly:sNy+Oly)
71    #else
72          _RL     cg3d_b(1)
73    #endif
74  CEOP  CEOP
75    
76    #ifdef ALLOW_NONHYDROSTATIC
77            zeroPsNH = .FALSE.
78    c       zeroPsNH = exactConserv
79    #else
80            cg3d_b(1) = 0.
81    #endif
82    
83    C deepAtmosphere & useRealFreshWaterFlux: only valid if deepFac2F(ksurf)=1
84    C anelastic (always Z-coordinate):
85    C     1) assume that rhoFacF(1)=1 (and ksurf == 1);
86    C        (this reduces the number of lines of code to modify)
87    C     2) (a) 2-D continuity eq. compute div. of mass transport (<- add rhoFac)
88    C        (b) gradient of surf.Press in momentum eq. (<- add 1/rhoFac)
89    C       => 2 factors cancel in elliptic eq. for Phi_s ,
90    C       but 1rst factor(a) remains in RHS cg2d_b.
91    
92    C--   Initialise the Vector solution with etaN + deltaT*Global_mean_PmE
93    C     instead of simply etaN ; This can speed-up the solver convergence in
94    C     the case where |Global_mean_PmE| is large.
95          putPmEinXvector = .FALSE.
96    c     putPmEinXvector = useRealFreshWaterFlux.AND.fluidIsWater
97    
98  C--   Save previous solution & Initialise Vector solution and source term :  C--   Save previous solution & Initialise Vector solution and source term :
99          sumEmP = 0.
100        DO bj=myByLo(myThid),myByHi(myThid)        DO bj=myByLo(myThid),myByHi(myThid)
101         DO bi=myBxLo(myThid),myBxHi(myThid)         DO bi=myBxLo(myThid),myBxHi(myThid)
102          DO j=1-OLy,sNy+OLy          DO j=1-OLy,sNy+OLy
103           DO i=1-OLx,sNx+OLx           DO i=1-OLx,sNx+OLx
104  #ifdef INCLUDE_CD_CODE  #ifdef ALLOW_CD_CODE
105            etaNm1(i,j,bi,bj) = etaN(i,j,bi,bj)            etaNm1(i,j,bi,bj) = etaN(i,j,bi,bj)
106  #endif  #endif
107            cg2d_x(i,j,bi,bj) = Bo_surf(i,j,bi,bj)*etaN(i,j,bi,bj)            cg2d_x(i,j,bi,bj) = Bo_surf(i,j,bi,bj)*etaN(i,j,bi,bj)
108            cg2d_b(i,j,bi,bj) = 0.            cg2d_b(i,j,bi,bj) = 0.
109           ENDDO           ENDDO
110          ENDDO          ENDDO
111          IF (useRealFreshWaterFlux) THEN          IF (useRealFreshWaterFlux.AND.fluidIsWater) THEN
112           tmpFac = freeSurfFac*convertEmP2rUnit           tmpFac = freeSurfFac*mass2rUnit
113           IF (exactConserv)           IF (exactConserv)
114       &        tmpFac = freeSurfFac*convertEmP2rUnit*implicDiv2DFlow       &        tmpFac = freeSurfFac*mass2rUnit*implicDiv2DFlow
115           DO j=1,sNy           DO j=1,sNy
116            DO i=1,sNx            DO i=1,sNx
117             cg2d_b(i,j,bi,bj) =             cg2d_b(i,j,bi,bj) =
118       &       tmpFac*_rA(i,j,bi,bj)*EmPmR(i,j,bi,bj)/deltaTMom       &       tmpFac*_rA(i,j,bi,bj)*EmPmR(i,j,bi,bj)/deltaTMom
119            ENDDO            ENDDO
120           ENDDO           ENDDO
121          ENDIF          ENDIF
122            IF ( putPmEinXvector ) THEN
123             tileEmP(bi,bj) = 0.
124             DO j=1,sNy
125              DO i=1,sNx
126                tileEmP(bi,bj) = tileEmP(bi,bj)
127         &                     + rA(i,j,bi,bj)*EmPmR(i,j,bi,bj)
128         &                                    *maskH(i,j,bi,bj)
129              ENDDO
130             ENDDO
131            ENDIF
132         ENDDO         ENDDO
133        ENDDO        ENDDO
134          IF ( putPmEinXvector ) THEN
135            CALL GLOBAL_SUM_TILE_RL( tileEmP, sumEmP, myThid )
136          ENDIF
137    
138        DO bj=myByLo(myThid),myByHi(myThid)        DO bj=myByLo(myThid),myByHi(myThid)
139         DO bi=myBxLo(myThid),myBxHi(myThid)         DO bi=myBxLo(myThid),myBxHi(myThid)
140          DO K=Nr,1,-1          IF ( putPmEinXvector ) THEN
141           DO j=1,sNy+1            tmpFac = 0.
142            DO i=1,sNx+1            IF (globalArea.GT.0.) tmpFac =
143             uf(i,j) = _dyG(i,j,bi,bj)       &      freeSurfFac*deltaTfreesurf*mass2rUnit*sumEmP/globalArea
144       &      *drF(k)*_hFacW(i,j,k,bi,bj)            DO j=1,sNy
145             vf(i,j) = _dxG(i,j,bi,bj)             DO i=1,sNx
146       &      *drF(k)*_hFacS(i,j,k,bi,bj)              cg2d_x(i,j,bi,bj) = cg2d_x(i,j,bi,bj)
147         &                        - tmpFac*Bo_surf(i,j,bi,bj)
148               ENDDO
149            ENDDO            ENDDO
150           ENDDO          ENDIF
151    C- RHS: similar to the divergence of the vertically integrated mass transport:
152    C       del_i { Sum_k [ rhoFac.(dr.hFac).(dy.deepFac).(u*) ] }  / deltaT
153            DO k=Nr,1,-1
154           CALL CALC_DIV_GHAT(           CALL CALC_DIV_GHAT(
155       I       bi,bj,1,sNx,1,sNy,K,       I                       bi,bj,k,
156       I       uf,vf,       U                       cg2d_b, cg3d_b,
157       U       cg2d_b,       I                       myThid )
      I       myThid)  
158          ENDDO          ENDDO
159         ENDDO         ENDDO
160        ENDDO        ENDDO
# Line 109  C--   Add source term arising from w=d/d Line 163  C--   Add source term arising from w=d/d
163        DO bj=myByLo(myThid),myByHi(myThid)        DO bj=myByLo(myThid),myByHi(myThid)
164         DO bi=myBxLo(myThid),myBxHi(myThid)         DO bi=myBxLo(myThid),myBxHi(myThid)
165  #ifdef ALLOW_NONHYDROSTATIC  #ifdef ALLOW_NONHYDROSTATIC
166          IF ( nonHydrostatic ) THEN          IF ( use3Dsolver .AND. zeroPsNH ) THEN
167           DO j=1,sNy           DO j=1,sNy
168            DO i=1,sNx            DO i=1,sNx
169             cg2d_b(i,j,bi,bj) = cg2d_b(i,j,bi,bj)             ks = ksurfC(i,j,bi,bj)
170       &       -freeSurfFac*_rA(i,j,bi,bj)/deltaTMom/deltaTfreesurf             IF ( ks.LE.Nr ) THEN
171                cg2d_b(i,j,bi,bj) = cg2d_b(i,j,bi,bj)
172         &       -freeSurfFac*_rA(i,j,bi,bj)*deepFac2F(ks)
173         &         /deltaTMom/deltaTfreesurf
174         &         * etaH(i,j,bi,bj)
175                cg3d_b(i,j,ks,bi,bj) = cg3d_b(i,j,ks,bi,bj)
176         &       -freeSurfFac*_rA(i,j,bi,bj)*deepFac2F(ks)
177         &         /deltaTMom/deltaTfreesurf
178         &         * etaH(i,j,bi,bj)
179               ENDIF
180              ENDDO
181             ENDDO
182            ELSEIF ( use3Dsolver ) THEN
183             DO j=1,sNy
184              DO i=1,sNx
185               ks = ksurfC(i,j,bi,bj)
186               IF ( ks.LE.Nr ) THEN
187                cg2d_b(i,j,bi,bj) = cg2d_b(i,j,bi,bj)
188         &       -freeSurfFac*_rA(i,j,bi,bj)*deepFac2F(ks)
189         &         /deltaTMom/deltaTfreesurf
190       &         *( etaN(i,j,bi,bj)       &         *( etaN(i,j,bi,bj)
191       &           +phi_nh(i,j,1,bi,bj)*horiVertRatio/gravity )       &           +phi_nh(i,j,ks,bi,bj)*recip_Bo(i,j,bi,bj) )
192             cg3d_b(i,j,1,bi,bj) = cg3d_b(i,j,1,bi,bj)              cg3d_b(i,j,ks,bi,bj) = cg3d_b(i,j,ks,bi,bj)
193       &       -freeSurfFac*_rA(i,j,bi,bj)/deltaTMom/deltaTfreesurf       &       -freeSurfFac*_rA(i,j,bi,bj)*deepFac2F(ks)
194         &         /deltaTMom/deltaTfreesurf
195       &         *( etaN(i,j,bi,bj)       &         *( etaN(i,j,bi,bj)
196       &           +phi_nh(i,j,1,bi,bj)*horiVertRatio/gravity )       &           +phi_nh(i,j,ks,bi,bj)*recip_Bo(i,j,bi,bj) )
197               ENDIF
198            ENDDO            ENDDO
199           ENDDO           ENDDO
200          ELSEIF ( exactConserv ) THEN          ELSEIF ( exactConserv ) THEN
201  #else  #else
202          IF ( exactConserv ) THEN          IF ( exactConserv ) THEN
203  #endif  #endif /* ALLOW_NONHYDROSTATIC */
204           DO j=1,sNy           DO j=1,sNy
205            DO i=1,sNx            DO i=1,sNx
206               ks = ksurfC(i,j,bi,bj)
207             cg2d_b(i,j,bi,bj) = cg2d_b(i,j,bi,bj)             cg2d_b(i,j,bi,bj) = cg2d_b(i,j,bi,bj)
208       &       -freeSurfFac*_rA(i,j,bi,bj)/deltaTMom/deltaTfreesurf       &       -freeSurfFac*_rA(i,j,bi,bj)*deepFac2F(ks)
209         &         /deltaTMom/deltaTfreesurf
210       &         * etaH(i,j,bi,bj)       &         * etaH(i,j,bi,bj)
211            ENDDO            ENDDO
212           ENDDO           ENDDO
213          ELSE          ELSE
214           DO j=1,sNy           DO j=1,sNy
215            DO i=1,sNx            DO i=1,sNx
216               ks = ksurfC(i,j,bi,bj)
217             cg2d_b(i,j,bi,bj) = cg2d_b(i,j,bi,bj)             cg2d_b(i,j,bi,bj) = cg2d_b(i,j,bi,bj)
218       &       -freeSurfFac*_rA(i,j,bi,bj)/deltaTMom/deltaTfreesurf       &       -freeSurfFac*_rA(i,j,bi,bj)*deepFac2F(ks)
219         &         /deltaTMom/deltaTfreesurf
220       &         * etaN(i,j,bi,bj)       &         * etaN(i,j,bi,bj)
221            ENDDO            ENDDO
222           ENDDO           ENDDO
# Line 147  C--   Add source term arising from w=d/d Line 226  C--   Add source term arising from w=d/d
226          IF (useOBCS) THEN          IF (useOBCS) THEN
227           DO i=1,sNx           DO i=1,sNx
228  C Northern boundary  C Northern boundary
229            IF (OB_Jn(I,bi,bj).NE.0) THEN            IF (OB_Jn(i,bi,bj).NE.0) THEN
230             cg2d_b(I,OB_Jn(I,bi,bj),bi,bj)=0.             cg2d_b(i,OB_Jn(i,bi,bj),bi,bj)=0.
231             cg2d_x(I,OB_Jn(I,bi,bj),bi,bj)=0.             cg2d_x(i,OB_Jn(i,bi,bj),bi,bj)=0.
232            ENDIF            ENDIF
233  C Southern boundary  C Southern boundary
234            IF (OB_Js(I,bi,bj).NE.0) THEN            IF (OB_Js(i,bi,bj).NE.0) THEN
235             cg2d_b(I,OB_Js(I,bi,bj),bi,bj)=0.             cg2d_b(i,OB_Js(i,bi,bj),bi,bj)=0.
236             cg2d_x(I,OB_Js(I,bi,bj),bi,bj)=0.             cg2d_x(i,OB_Js(i,bi,bj),bi,bj)=0.
237            ENDIF            ENDIF
238           ENDDO           ENDDO
239           DO j=1,sNy           DO j=1,sNy
240  C Eastern boundary  C Eastern boundary
241            IF (OB_Ie(J,bi,bj).NE.0) THEN            IF (OB_Ie(j,bi,bj).NE.0) THEN
242             cg2d_b(OB_Ie(J,bi,bj),J,bi,bj)=0.             cg2d_b(OB_Ie(j,bi,bj),j,bi,bj)=0.
243             cg2d_x(OB_Ie(J,bi,bj),J,bi,bj)=0.             cg2d_x(OB_Ie(j,bi,bj),j,bi,bj)=0.
244            ENDIF            ENDIF
245  C Western boundary  C Western boundary
246            IF (OB_Iw(J,bi,bj).NE.0) THEN            IF (OB_Iw(j,bi,bj).NE.0) THEN
247             cg2d_b(OB_Iw(J,bi,bj),J,bi,bj)=0.             cg2d_b(OB_Iw(j,bi,bj),j,bi,bj)=0.
248             cg2d_x(OB_Iw(J,bi,bj),J,bi,bj)=0.             cg2d_x(OB_Iw(j,bi,bj),j,bi,bj)=0.
249            ENDIF            ENDIF
250           ENDDO           ENDDO
251          ENDIF          ENDIF
252  #endif  #endif /* ALLOW_OBCS */
253    C-    end bi,bj loops
254         ENDDO         ENDDO
255        ENDDO        ENDDO
256    
257  #ifndef DISABLE_DEBUGMODE  #ifdef ALLOW_DEBUG
258        IF (debugMode) THEN        IF ( debugLevel .GE. debLevB ) THEN
259         CALL DEBUG_STATS_RL(1,cg2d_b,'cg2d_b (SOLVE_FOR_PRESSURE)',         CALL DEBUG_STATS_RL(1,cg2d_b,'cg2d_b (SOLVE_FOR_PRESSURE)',
260       &                        myThid)       &                        myThid)
261        ENDIF        ENDIF
262  #endif  #endif
263          IF ( DIFFERENT_MULTIPLE(diagFreq, myTime, deltaTClock) ) THEN
264           WRITE(sufx,'(I10.10)') myIter
265           CALL WRITE_FLD_XY_RL( 'cg2d_b.', sufx, cg2d_b, myIter, myThid )
266          ENDIF
267    
268  C--   Find the surface pressure using a two-dimensional conjugate  C--   Find the surface pressure using a two-dimensional conjugate
269  C--   gradient solver.  C--   gradient solver.
# Line 187  C     see CG2D.h for the interface to th Line 271  C     see CG2D.h for the interface to th
271        firstResidual=0.        firstResidual=0.
272        lastResidual=0.        lastResidual=0.
273        numIters=cg2dMaxIters        numIters=cg2dMaxIters
274        CALL CG2D(  c     CALL TIMER_START('CG2D   [SOLVE_FOR_PRESSURE]',myThid)
275    #ifdef ALLOW_CG2D_NSA
276    C--   Call the not-self-adjoint version of cg2d
277          CALL CG2D_NSA(
278         U           cg2d_b,
279         U           cg2d_x,
280         O           firstResidual,
281         O           lastResidual,
282         U           numIters,
283         I           myThid )
284    #else /* not ALLOW_CG2D_NSA = default */
285    #ifdef ALLOW_SRCG
286          IF ( useSRCGSolver ) THEN
287    C--   Call the single reduce CG solver
288           CALL CG2D_SR(
289       U           cg2d_b,       U           cg2d_b,
290       U           cg2d_x,       U           cg2d_x,
291       O           firstResidual,       O           firstResidual,
292       O           lastResidual,       O           lastResidual,
293       U           numIters,       U           numIters,
294       I           myThid )       I           myThid )
295        _EXCH_XY_R8(cg2d_x, myThid )        ELSE
296    #else
297          IF (.TRUE.) THEN
298    C--   Call the default CG solver
299    #endif /* ALLOW_SRCG */
300           CALL CG2D(
301         U           cg2d_b,
302         U           cg2d_x,
303         O           firstResidual,
304         O           lastResidual,
305         U           numIters,
306         I           myThid )
307          ENDIF
308    #endif /* ALLOW_CG2D_NSA */
309          _EXCH_XY_RL( cg2d_x, myThid )
310    c     CALL TIMER_STOP ('CG2D   [SOLVE_FOR_PRESSURE]',myThid)
311    
312  #ifndef DISABLE_DEBUGMODE  #ifdef ALLOW_DEBUG
313        IF (debugMode) THEN        IF ( debugLevel .GE. debLevB ) THEN
314         CALL DEBUG_STATS_RL(1,cg2d_x,'cg2d_x (SOLVE_FOR_PRESSURE)',         CALL DEBUG_STATS_RL(1,cg2d_x,'cg2d_x (SOLVE_FOR_PRESSURE)',
315       &                        myThid)       &                        myThid)
316        ENDIF        ENDIF
317  #endif  #endif
318    
319  C- dump CG2D output at monitorFreq (to reduce size of STD-OUTPUT files) :  C- dump CG2D output at monitorFreq (to reduce size of STD-OUTPUT files) :
320        IF ( DIFFERENT_MULTIPLE(monitorFreq,myTime,        IF ( DIFFERENT_MULTIPLE(monitorFreq,myTime,deltaTClock)
321       &                                    myTime-deltaTClock) ) THEN       &   ) THEN
322         _BEGIN_MASTER( myThid )         IF ( debugLevel .GE. debLevA ) THEN
323         WRITE(msgBuf,'(A34,1PE24.14)') 'cg2d_init_res =',firstResidual          _BEGIN_MASTER( myThid )
324         CALL PRINT_MESSAGE(msgBuf,standardMessageUnit,SQUEEZE_RIGHT,1)          WRITE(msgBuf,'(A34,1PE24.14)') 'cg2d_init_res =',firstResidual
325         WRITE(msgBuf,'(A34,I6)') 'cg2d_iters =',numIters          CALL PRINT_MESSAGE(msgBuf,standardMessageUnit,SQUEEZE_RIGHT,1)
326         CALL PRINT_MESSAGE(msgBuf,standardMessageUnit,SQUEEZE_RIGHT,1)          WRITE(msgBuf,'(A34,I6)') 'cg2d_iters =',numIters
327         WRITE(msgBuf,'(A34,1PE24.14)') 'cg2d_res =',lastResidual          CALL PRINT_MESSAGE(msgBuf,standardMessageUnit,SQUEEZE_RIGHT,1)
328         CALL PRINT_MESSAGE(msgBuf,standardMessageUnit,SQUEEZE_RIGHT,1)          WRITE(msgBuf,'(A34,1PE24.14)') 'cg2d_res =',lastResidual
329         _END_MASTER( )          CALL PRINT_MESSAGE(msgBuf,standardMessageUnit,SQUEEZE_RIGHT,1)
330            _END_MASTER( myThid )
331           ENDIF
332        ENDIF        ENDIF
333    
334  C--   Transfert the 2D-solution to "etaN" :  C--   Transfert the 2D-solution to "etaN" :
# Line 228  C--   Transfert the 2D-solution to "etaN Line 343  C--   Transfert the 2D-solution to "etaN
343        ENDDO        ENDDO
344    
345  #ifdef ALLOW_NONHYDROSTATIC  #ifdef ALLOW_NONHYDROSTATIC
346        IF ( nonHydrostatic ) THEN        IF ( use3Dsolver ) THEN
347           IF ( DIFFERENT_MULTIPLE(diagFreq, myTime, deltaTClock) ) THEN
348            WRITE(sufx,'(I10.10)') myIter
349            CALL WRITE_FLD_XY_RL( 'cg2d_x.',sufx, cg2d_x, myIter, myThid )
350           ENDIF
351    
352  C--   Solve for a three-dimensional pressure term (NH or IGW or both ).  C--   Solve for a three-dimensional pressure term (NH or IGW or both ).
353  C     see CG3D.h for the interface to this routine.  C     see CG3D.h for the interface to this routine.
# Line 247  C     see CG3D.h for the interface to th Line 366  C     see CG3D.h for the interface to th
366           IF (useOBCS) THEN           IF (useOBCS) THEN
367            DO i=1,sNx+1            DO i=1,sNx+1
368  C Northern boundary  C Northern boundary
369            IF (OB_Jn(I,bi,bj).NE.0) THEN            IF (OB_Jn(i,bi,bj).NE.0) THEN
370             vf(I,OB_Jn(I,bi,bj))=0.             vf(i,OB_Jn(i,bi,bj))=0.
371            ENDIF            ENDIF
372  C Southern boundary  C Southern boundary
373            IF (OB_Js(I,bi,bj).NE.0) THEN            IF (OB_Js(i,bi,bj).NE.0) THEN
374             vf(I,OB_Js(I,bi,bj)+1)=0.             vf(i,OB_Js(i,bi,bj)+1)=0.
375            ENDIF            ENDIF
376            ENDDO            ENDDO
377            DO j=1,sNy+1            DO j=1,sNy+1
378  C Eastern boundary  C Eastern boundary
379            IF (OB_Ie(J,bi,bj).NE.0) THEN            IF (OB_Ie(j,bi,bj).NE.0) THEN
380             uf(OB_Ie(J,bi,bj),J)=0.             uf(OB_Ie(j,bi,bj),j)=0.
381            ENDIF            ENDIF
382  C Western boundary  C Western boundary
383            IF (OB_Iw(J,bi,bj).NE.0) THEN            IF (OB_Iw(j,bi,bj).NE.0) THEN
384             uf(OB_Iw(J,bi,bj)+1,J)=0.             uf(OB_Iw(j,bi,bj)+1,J)=0.
385            ENDIF            ENDIF
386            ENDDO            ENDDO
387           ENDIF           ENDIF
388  #endif  #endif /* ALLOW_OBCS */
389    
390           K=1           IF ( usingZCoords ) THEN
391    C-       Z coordinate: assume surface @ level k=1
392               tmpFac = freeSurfFac*deepFac2F(1)
393             ELSE
394    C-       Other than Z coordinate: no assumption on surface level index
395               tmpFac = 0.
396               DO j=1,sNy
397                DO i=1,sNx
398                  ks = ksurfC(i,j,bi,bj)
399                  IF ( ks.LE.Nr ) THEN
400                   cg3d_b(i,j,ks,bi,bj) = cg3d_b(i,j,ks,bi,bj)
401         &              +freeSurfFac*etaN(i,j,bi,bj)/deltaTfreesurf
402         &                  *_rA(i,j,bi,bj)*deepFac2F(ks)/deltaTmom
403                  ENDIF
404                ENDDO
405               ENDDO
406             ENDIF
407             k=1
408             kp1 = MIN(k+1,Nr)
409             wFacKp = deepFac2F(kp1)*rhoFacF(kp1)
410             IF (k.GE.Nr) wFacKp = 0.
411           DO j=1,sNy           DO j=1,sNy
412            DO i=1,sNx            DO i=1,sNx
413             cg3d_b(i,j,k,bi,bj) = cg3d_b(i,j,k,bi,bj)              cg3d_b(i,j,k,bi,bj) = cg3d_b(i,j,k,bi,bj)
414       &       +dRF(K)*dYG(i+1,j,bi,bj)*hFacW(i+1,j,k,bi,bj)*uf(i+1,j)       &       +drF(k)*dyG(i+1,j,bi,bj)*_hFacW(i+1,j,k,bi,bj)*uf(i+1,j)
415       &       -dRF(K)*dYG( i ,j,bi,bj)*hFacW( i ,j,k,bi,bj)*uf( i ,j)       &       -drF(k)*dyG( i ,j,bi,bj)*_hFacW( i ,j,k,bi,bj)*uf( i ,j)
416       &       +dRF(K)*dXG(i,j+1,bi,bj)*hFacS(i,j+1,k,bi,bj)*vf(i,j+1)       &       +drF(k)*dxG(i,j+1,bi,bj)*_hFacS(i,j+1,k,bi,bj)*vf(i,j+1)
417       &       -dRF(K)*dXG(i, j ,bi,bj)*hFacS(i, j ,k,bi,bj)*vf(i, j )       &       -drF(k)*dxG(i, j ,bi,bj)*_hFacS(i, j ,k,bi,bj)*vf(i, j )
418       &       +( freeSurfFac*etaN(i,j,bi,bj)/deltaTMom       &       +( tmpFac*etaN(i,j,bi,bj)/deltaTfreesurf
419       &          -wVel(i,j,k+1,bi,bj)       &         -wVel(i,j,kp1,bi,bj)*wFacKp
420       &        )*_rA(i,j,bi,bj)/deltaTmom       &        )*_rA(i,j,bi,bj)/deltaTmom
421            ENDDO            ENDDO
422           ENDDO           ENDDO
423           DO K=2,Nr-1           DO k=2,Nr
424              kp1 = MIN(k+1,Nr)
425    C-       deepFac & rhoFac cancel with the ones in uf[=del_i(Phi)/dx],vf ;
426    C        both appear in wVel term, but at 2 different levels
427              wFacKm = deepFac2F( k )*rhoFacF( k )
428              wFacKp = deepFac2F(kp1)*rhoFacF(kp1)
429              IF (k.GE.Nr) wFacKp = 0.
430            DO j=1,sNy            DO j=1,sNy
431             DO i=1,sNx             DO i=1,sNx
432              cg3d_b(i,j,k,bi,bj) = cg3d_b(i,j,k,bi,bj)              cg3d_b(i,j,k,bi,bj) = cg3d_b(i,j,k,bi,bj)
433       &       +dRF(K)*dYG(i+1,j,bi,bj)*hFacW(i+1,j,k,bi,bj)*uf(i+1,j)       &       +drF(k)*dyG(i+1,j,bi,bj)*_hFacW(i+1,j,k,bi,bj)*uf(i+1,j)
434       &       -dRF(K)*dYG( i ,j,bi,bj)*hFacW( i ,j,k,bi,bj)*uf( i ,j)       &       -drF(k)*dyG( i ,j,bi,bj)*_hFacW( i ,j,k,bi,bj)*uf( i ,j)
435       &       +dRF(K)*dXG(i,j+1,bi,bj)*hFacS(i,j+1,k,bi,bj)*vf(i,j+1)       &       +drF(k)*dxG(i,j+1,bi,bj)*_hFacS(i,j+1,k,bi,bj)*vf(i,j+1)
436       &       -dRF(K)*dXG(i, j ,bi,bj)*hFacS(i, j ,k,bi,bj)*vf(i, j )       &       -drF(k)*dxG(i, j ,bi,bj)*_hFacS(i, j ,k,bi,bj)*vf(i, j )
437       &       +( wVel(i,j,k  ,bi,bj)       &       +( wVel(i,j, k ,bi,bj)*wFacKm*maskC(i,j,k-1,bi,bj)
438       &         -wVel(i,j,k+1,bi,bj)       &         -wVel(i,j,kp1,bi,bj)*wFacKp
439       &        )*_rA(i,j,bi,bj)/deltaTmom       &        )*_rA(i,j,bi,bj)/deltaTmom
440    
441             ENDDO             ENDDO
442            ENDDO            ENDDO
443           ENDDO           ENDDO
          K=Nr  
          DO j=1,sNy  
           DO i=1,sNx  
             cg3d_b(i,j,k,bi,bj) = cg3d_b(i,j,k,bi,bj)  
      &       +dRF(K)*dYG(i+1,j,bi,bj)*hFacW(i+1,j,k,bi,bj)*uf(i+1,j)  
      &       -dRF(K)*dYG( i ,j,bi,bj)*hFacW( i ,j,k,bi,bj)*uf( i ,j)  
      &       +dRF(K)*dXG(i,j+1,bi,bj)*hFacS(i,j+1,k,bi,bj)*vf(i,j+1)  
      &       -dRF(K)*dXG(i, j ,bi,bj)*hFacS(i, j ,k,bi,bj)*vf(i, j )  
      &       +( wVel(i,j,k  ,bi,bj)  
      &        )*_rA(i,j,bi,bj)/deltaTmom  
   
           ENDDO  
          ENDDO  
444    
445  #ifdef ALLOW_OBCS  #ifdef ALLOW_OBCS
446           IF (useOBCS) THEN           IF (useOBCS) THEN
447            DO K=1,Nr            DO k=1,Nr
448            DO i=1,sNx            DO i=1,sNx
449  C Northern boundary  C Northern boundary
450            IF (OB_Jn(I,bi,bj).NE.0) THEN            IF (OB_Jn(i,bi,bj).NE.0) THEN
451             cg3d_b(I,OB_Jn(I,bi,bj),K,bi,bj)=0.             cg3d_b(i,OB_Jn(i,bi,bj),k,bi,bj)=0.
452            ENDIF            ENDIF
453  C Southern boundary  C Southern boundary
454            IF (OB_Js(I,bi,bj).NE.0) THEN            IF (OB_Js(i,bi,bj).NE.0) THEN
455             cg3d_b(I,OB_Js(I,bi,bj),K,bi,bj)=0.             cg3d_b(i,OB_Js(i,bi,bj),k,bi,bj)=0.
456            ENDIF            ENDIF
457            ENDDO            ENDDO
458            DO j=1,sNy            DO j=1,sNy
459  C Eastern boundary  C Eastern boundary
460            IF (OB_Ie(J,bi,bj).NE.0) THEN            IF (OB_Ie(j,bi,bj).NE.0) THEN
461             cg3d_b(OB_Ie(J,bi,bj),J,K,bi,bj)=0.             cg3d_b(OB_Ie(j,bi,bj),j,k,bi,bj)=0.
462            ENDIF            ENDIF
463  C Western boundary  C Western boundary
464            IF (OB_Iw(J,bi,bj).NE.0) THEN            IF (OB_Iw(j,bi,bj).NE.0) THEN
465             cg3d_b(OB_Iw(J,bi,bj),J,K,bi,bj)=0.             cg3d_b(OB_Iw(j,bi,bj),j,k,bi,bj)=0.
466            ENDIF            ENDIF
467            ENDDO            ENDDO
468            ENDDO            ENDDO
469           ENDIF           ENDIF
470  #endif  #endif /* ALLOW_OBCS */
471    C-    end bi,bj loops
472            ENDDO
473           ENDDO
474    
475          ENDDO ! bi  #ifdef ALLOW_DEBUG
476         ENDDO ! bj        IF ( debugLevel .GE. debLevB ) THEN
477           CALL DEBUG_STATS_RL(Nr,cg3d_b,'cg3d_b (SOLVE_FOR_PRESSURE)',
478         &                        myThid)
479          ENDIF
480    #endif
481          IF ( DIFFERENT_MULTIPLE( diagFreq, myTime, deltaTClock) ) THEN
482           WRITE(sufx,'(I10.10)') myIter
483           CALL WRITE_FLD_XYZ_RL( 'cg3d_b.',sufx, cg3d_b, myIter, myThid )
484          ENDIF
485    
486        firstResidual=0.        firstResidual=0.
487        lastResidual=0.        lastResidual=0.
488        numIters=cg2dMaxIters        numIters=cg3dMaxIters
489          CALL TIMER_START('CG3D   [SOLVE_FOR_PRESSURE]',myThid)
490        CALL CG3D(        CALL CG3D(
491       U           cg3d_b,       U           cg3d_b,
492       U           phi_nh,       U           phi_nh,
# Line 350  C Western boundary Line 494  C Western boundary
494       O           lastResidual,       O           lastResidual,
495       U           numIters,       U           numIters,
496       I           myThid )       I           myThid )
497        _EXCH_XYZ_R8(phi_nh, myThid )        _EXCH_XYZ_RL( phi_nh, myThid )
498          CALL TIMER_STOP ('CG3D   [SOLVE_FOR_PRESSURE]',myThid)
499    
500        IF ( DIFFERENT_MULTIPLE(monitorFreq,myTime,        IF ( DIFFERENT_MULTIPLE(monitorFreq,myTime,deltaTClock)
501       &                                    myTime-deltaTClock) ) THEN       &   ) THEN
502         _BEGIN_MASTER( myThid )         IF ( debugLevel .GE. debLevA ) THEN
503         WRITE(msgBuf,'(A34,1PE24.14)') 'cg3d_init_res =',firstResidual          _BEGIN_MASTER( myThid )
504         CALL PRINT_MESSAGE(msgBuf,standardMessageUnit,SQUEEZE_RIGHT,1)          WRITE(msgBuf,'(A34,1PE24.14)') 'cg3d_init_res =',firstResidual
505         WRITE(msgBuf,'(A34,I6)') 'cg3d_iters =',numIters          CALL PRINT_MESSAGE(msgBuf,standardMessageUnit,SQUEEZE_RIGHT,1)
506         CALL PRINT_MESSAGE(msgBuf,standardMessageUnit,SQUEEZE_RIGHT,1)          WRITE(msgBuf,'(A34,I6)') 'cg3d_iters =',numIters
507         WRITE(msgBuf,'(A34,1PE24.14)') 'cg3d_res =',lastResidual          CALL PRINT_MESSAGE(msgBuf,standardMessageUnit,SQUEEZE_RIGHT,1)
508         CALL PRINT_MESSAGE(msgBuf,standardMessageUnit,SQUEEZE_RIGHT,1)          WRITE(msgBuf,'(A34,1PE24.14)') 'cg3d_res =',lastResidual
509         _END_MASTER( )          CALL PRINT_MESSAGE(msgBuf,standardMessageUnit,SQUEEZE_RIGHT,1)
510            _END_MASTER( myThid )
511           ENDIF
512        ENDIF        ENDIF
513    
514    C--   Update surface pressure (account for NH-p @ surface level) and NH pressure:
515          IF ( zeroPsNH ) THEN
516           IF ( DIFFERENT_MULTIPLE( diagFreq, myTime, deltaTClock) ) THEN
517            WRITE(sufx,'(I10.10)') myIter
518            CALL WRITE_FLD_XYZ_RL( 'cg3d_x.',sufx,phi_nh, myIter, myThid )
519           ENDIF
520           DO bj=myByLo(myThid),myByHi(myThid)
521            DO bi=myBxLo(myThid),myBxHi(myThid)
522    
523             IF ( usingZCoords ) THEN
524    C-       Z coordinate: assume surface @ level k=1
525              DO k=2,Nr
526               DO j=1-OLy,sNy+OLy
527                DO i=1-OLx,sNx+OLx
528                 phi_nh(i,j,k,bi,bj) = phi_nh(i,j,k,bi,bj)
529         &                           - phi_nh(i,j,1,bi,bj)
530                ENDDO
531               ENDDO
532              ENDDO
533              DO j=1-OLy,sNy+OLy
534               DO i=1-OLx,sNx+OLx
535                 etaN(i,j,bi,bj) = recip_Bo(i,j,bi,bj)
536         &                       *(cg2d_x(i,j,bi,bj) + phi_nh(i,j,1,bi,bj))
537                 phi_nh(i,j,1,bi,bj) = 0.
538               ENDDO
539              ENDDO
540             ELSE
541    C-       Other than Z coordinate: no assumption on surface level index
542              DO j=1-OLy,sNy+OLy
543               DO i=1-OLx,sNx+OLx
544                ks = ksurfC(i,j,bi,bj)
545                IF ( ks.LE.Nr ) THEN
546                 etaN(i,j,bi,bj) = recip_Bo(i,j,bi,bj)
547         &                       *(cg2d_x(i,j,bi,bj) + phi_nh(i,j,ks,bi,bj))
548                 DO k=Nr,1,-1
549                  phi_nh(i,j,k,bi,bj) = phi_nh(i,j,k,bi,bj)
550         &                            - phi_nh(i,j,ks,bi,bj)
551                 ENDDO
552                ENDIF
553               ENDDO
554              ENDDO
555             ENDIF
556    
557            ENDDO
558           ENDDO
559        ENDIF        ENDIF
560    
561          ENDIF
562    #endif /* ALLOW_NONHYDROSTATIC */
563    
564    #ifdef ALLOW_SHOWFLOPS
565          CALL SHOWFLOPS_INSOLVE( myThid)
566  #endif  #endif
567    
568        RETURN        RETURN

Legend:
Removed from v.1.37  
changed lines
  Added in v.1.69

  ViewVC Help
Powered by ViewVC 1.1.22