/[MITgcm]/MITgcm/pkg/seaice/seaice_jfnk.F
ViewVC logotype

Diff of /MITgcm/pkg/seaice/seaice_jfnk.F

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

revision 1.3 by mlosch, Tue Nov 6 12:53:14 2012 UTC revision 1.13 by mlosch, Mon Dec 17 15:06:02 2012 UTC
# Line 51  C     myThid :: my Thread Id. number Line 51  C     myThid :: my Thread Id. number
51  #if ( (defined SEAICE_CGRID) && \  #if ( (defined SEAICE_CGRID) && \
52        (defined SEAICE_ALLOW_JFNK) && \        (defined SEAICE_ALLOW_JFNK) && \
53        (defined SEAICE_ALLOW_DYNAMICS) )        (defined SEAICE_ALLOW_DYNAMICS) )
54    C     !FUNCTIONS:
55          LOGICAL  DIFFERENT_MULTIPLE
56          EXTERNAL DIFFERENT_MULTIPLE
57    
58  C     i,j,bi,bj :: loop indices  C     i,j,bi,bj :: loop indices
59        INTEGER i,j,bi,bj        INTEGER i,j,bi,bj
60  C     loop indices  C     loop indices
61        INTEGER newtonIter, newtonIterFail        INTEGER newtonIter
62        INTEGER krylovIter, krylovIterFail        INTEGER krylovIter, krylovFails
63        INTEGER totalKrylovIter        INTEGER totalKrylovItersLoc, totalNewtonItersLoc
64  C     FGMRES flag that indicates what to do next  C     FGMRES flag that determines amount of output messages of fgmres
65          INTEGER iOutFGMRES
66    C     FGMRES flag that indicates what fgmres wants us to do next
67        INTEGER iCode        INTEGER iCode
68        _RL     JFNKresidual, JFNKresidualTile(nSx,nSy)        _RL     JFNKresidual
69        _RL     JFNKresidualKm1        _RL     JFNKresidualKm1
70  C     parameters to compute convergence criterion  C     parameters to compute convergence criterion
71        _RL     phi_e, alp_e, JFNKgamma_lin        _RL     phi_e, alp_e, JFNKgamma_lin
# Line 69  C     parameters to compute convergence Line 74  C     parameters to compute convergence
74  C      C    
75        _RL     recip_deltaT        _RL     recip_deltaT
76        LOGICAL JFNKconverged, krylovConverged        LOGICAL JFNKconverged, krylovConverged
77          LOGICAL writeNow
78        CHARACTER*(MAX_LEN_MBUF) msgBuf        CHARACTER*(MAX_LEN_MBUF) msgBuf
79  C  C
80  C     u/vIceRes :: residual of sea-ice momentum equations  C     u/vIceRes :: residual of sea-ice momentum equations
# Line 81  C     precomputed (= constant per Newton Line 87  C     precomputed (= constant per Newton
87  C     zeta, eta, and DWATN, press  C     zeta, eta, and DWATN, press
88        _RL zetaPre (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)        _RL zetaPre (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
89        _RL etaPre  (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)        _RL etaPre  (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
90          _RL etaZPre (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
91        _RL dwatPre (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)        _RL dwatPre (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
       _RL pressPre(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)  
92  CEOP  CEOP
93          INTEGER n
94          _RL resTmp (nVec,1,nSx,nSy)
95    
96  C     Initialise  C     Initialise
97        newtonIter      = 0        newtonIter          = 0
98        newtonIterFail  = 0        krylovFails         = 0
99        krylovIterFail  = 0        totalKrylovItersLoc = 0
100        totalKrylovIter = 0        JFNKconverged       = .FALSE.
101        JFNKconverged   = .FALSE.        JFNKtol             = 0. _d 0
102        JFNKtol         = 0. _d 0        JFNKresidual        = 0. _d 0
103        JFNKresidual    = 0. _d 0        JFNKresidualKm1     = 0. _d 0
104        JFNKresidualKm1 = 0. _d 0        FGMRESeps           = 0. _d 0
105        FGMRESeps       = 0. _d 0        recip_deltaT        = 1. _d 0 / SEAICE_deltaTdyn
106        recip_deltaT    = 1. _d 0 / SEAICE_deltaTdyn  
107          iOutFGMRES=0
108    C     with iOutFgmres=1, seaice_fgmres prints the residual at each iteration
109          IF ( debugLevel.GE.debLevC .AND.
110         &     DIFFERENT_MULTIPLE( SEAICE_monFreq, myTime, deltaTClock ) )
111         &     iOutFGMRES=1
112    
113  C      C    
114        DO bj=myByLo(myThid),myByHi(myThid)        DO bj=myByLo(myThid),myByHi(myThid)
115         DO bi=myBxLo(myThid),myBxHi(myThid)         DO bi=myBxLo(myThid),myBxHi(myThid)
# Line 132  C     variables DWATN, zeta, and eta) Line 146  C     variables DWATN, zeta, and eta)
146       I      uIce, vIce,       I      uIce, vIce,
147       O      uIceRes, vIceRes,       O      uIceRes, vIceRes,
148       I      newtonIter, 0, myTime, myIter, myThid )       I      newtonIter, 0, myTime, myIter, myThid )
149    C     probably not necessary, will be removed later:
150         CALL EXCH_UV_XY_RL( uIceRes, vIceRes,.TRUE.,myThid)         CALL EXCH_UV_XY_RL( uIceRes, vIceRes,.TRUE.,myThid)
151  C     local copies of precomputed coefficients that are to stay  C     local copies of precomputed coefficients that are to stay
152  C     constant for the preconditioner  C     constant for the preconditioner
# Line 139  C     constant for the preconditioner Line 154  C     constant for the preconditioner
154          DO bi=myBxLo(myThid),myBxHi(myThid)          DO bi=myBxLo(myThid),myBxHi(myThid)
155           DO j=1-Oly,sNy+Oly           DO j=1-Oly,sNy+Oly
156            DO i=1-Olx,sNx+Olx            DO i=1-Olx,sNx+Olx
157              zetaPre(I,J,bi,bj) =  zeta(I,J,bi,bj)             zetaPre(I,J,bi,bj) =  zeta(I,J,bi,bj)
158               etaPre(I,J,bi,bj) =   eta(I,J,bi,bj)              etaPre(I,J,bi,bj) =   eta(I,J,bi,bj)
159              dwatPre(I,J,bi,bj) = DWATN(I,J,bi,bj)             etaZPre(I,J,bi,bj) =  etaZ(I,J,bi,bj)
160             pressPre(I,J,bi,bj) = press(I,J,bi,bj)             dwatPre(I,J,bi,bj) = DWATN(I,J,bi,bj)
161            ENDDO            ENDDO
162           ENDDO           ENDDO
163          ENDDO          ENDDO
164         ENDDO         ENDDO
165  C      C     Important: Compute the norm of the residual using the same scalar
166         DO bj=myByLo(myThid),myByHi(myThid)  C     product that SEAICE_FGMRES does
167          DO bi=myBxLo(myThid),myBxHi(myThid)         CALL SEAICE_MAP2VEC(nVec,uIceRes,vIceRes,resTmp,.TRUE.,myThid)
168           JFNKresidualTile(bi,bj) = 0. _d 0         CALL SEAICE_SCALPROD(
169           DO J=1,sNy       &      nVec,1,1,1,resTmp,resTmp,JFNKresidual,myThid)
           DO I=1,sNx  
 #ifdef CG2D_SINGLECPU_SUM  
            JFNKlocalBuf(I,J,bi,bj) =  
 #else  
            JFNKresidualTile(bi,bj) = JFNKresidualTile(bi,bj) +  
 #endif  
      &          uIceRes(I,J,bi,bj)*uIceRes(I,J,bi,bj) +  
      &          vIceRes(I,J,bi,bj)*vIceRes(I,J,bi,bj)  
           ENDDO  
          ENDDO  
         ENDDO  
        ENDDO  
        JFNKresidual = 0. _d 0  
 #ifdef CG2D_SINGLECPU_SUM  
        CALL GLOBAL_SUM_SINGLECPU_RL(  
      &         JFNKlocalBuf,JFNKresidual, 0, 0, myThid)  
 #else  
        CALL GLOBAL_SUM_TILE_RL( JFNKresidualTile,JFNKresidual,myThid )  
 #endif  
170         JFNKresidual = SQRT(JFNKresidual)         JFNKresidual = SQRT(JFNKresidual)
171  C     compute convergence criterion for linear preconditioned FGMRES  C     compute convergence criterion for linear preconditioned FGMRES
172         JFNKgamma_lin = JFNKgamma_lin_max         JFNKgamma_lin = JFNKgamma_lin_max
# Line 193  C     krylovIter is mapped into "its" in Line 189  C     krylovIter is mapped into "its" in
189  C     in that routine  C     in that routine
190         krylovIter    = 0         krylovIter    = 0
191         iCode         = 0         iCode         = 0
        IF ( debugLevel.GE.debLevA ) THEN    
         WRITE(msgBuf,'(2A,2(1XI6),2E12.5)')  
      &       ' S/R SEAICE_JFNK: newtonIter,',  
      &       ' total newtonIter, JFNKgamma_lin, initial norm = ',  
      &       newtonIter,SEAICEnewtonIterMax*(myIter-nIter0)+newtonIter,  
      &       JFNKgamma_lin, JFNKresidual  
         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,  
      &       SQUEEZE_RIGHT, myThid )  
        ENDIF  
192  C  C
193         JFNKconverged = JFNKresidual.LT.JFNKtol         JFNKconverged = JFNKresidual.LT.JFNKtol
194  C  C
# Line 221  C Line 208  C
208           CALL SEAICE_FGMRES_DRIVER(           CALL SEAICE_FGMRES_DRIVER(
209       I        uIceRes, vIceRes,       I        uIceRes, vIceRes,
210       U        duIce, dvIce, iCode,       U        duIce, dvIce, iCode,
211       I        FGMRESeps,         I        FGMRESeps, iOutFGMRES,
212       I        newtonIter, krylovIter, myTime, myIter, myThid )       I        newtonIter, krylovIter, myTime, myIter, myThid )
213  C     FGMRES returns iCode either asking for an new preconditioned vector  C     FGMRES returns iCode either asking for an new preconditioned vector
214  C     or product of matrix (Jacobian) times vector. For iCode = 0, terminate  C     or product of matrix (Jacobian) times vector. For iCode = 0, terminate
215  C     iteration  C     iteration
216           IF (iCode.EQ.1) THEN           IF (iCode.EQ.1) THEN
217  C     Call preconditioner  C     Call preconditioner
218            CALL SEAICE_PRECONDITIONER(            IF ( SOLV_MAX_ITERS .GT. 0 )
219         &         CALL SEAICE_PRECONDITIONER(
220       U         duIce, dvIce,       U         duIce, dvIce,
221       I         zetaPre, etaPre, dwatPre, pressPre,       I         zetaPre, etaPre, etaZpre, dwatPre,
222       I         newtonIter, krylovIter, myTime, myIter, myThid )       I         newtonIter, krylovIter, myTime, myIter, myThid )
223           ELSEIF (iCode.GE.2) THEN           ELSEIF (iCode.GE.2) THEN
224  C     Compute Jacobian times vector  C     Compute Jacobian times vector
# Line 242  C     Compute Jacobian times vector Line 230  C     Compute Jacobian times vector
230           krylovConverged = iCode.EQ.0           krylovConverged = iCode.EQ.0
231  C     End of Krylov iterate  C     End of Krylov iterate
232          ENDDO          ENDDO
233          totalKrylovIter = totalKrylovIter + krylovIter          totalKrylovItersLoc = totalKrylovItersLoc + krylovIter
234  C     some output diagnostics  C     some output diagnostics
235          IF ( debugLevel.GE.debLevA ) THEN          IF ( debugLevel.GE.debLevA ) THEN
236             _BEGIN_MASTER( myThid )
237             totalNewtonItersLoc =
238         &        SEAICEnewtonIterMax*(myIter-nIter0)+newtonIter
239             WRITE(msgBuf,'(2A,2(1XI6),2E12.5)')
240         &        ' S/R SEAICE_JFNK: Newton iterate / total, ',
241         &        'JFNKgamma_lin, initial norm = ',
242         &        newtonIter, totalNewtonItersLoc,
243         &        JFNKgamma_lin,JFNKresidual
244             CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
245         &        SQUEEZE_RIGHT, myThid )
246           WRITE(msgBuf,'(3(A,I6))')           WRITE(msgBuf,'(3(A,I6))')
247       &        ' S/R SEAICE_JFNK: Newton iterate / total = ', newtonIter,       &        ' S/R SEAICE_JFNK: Newton iterate / total = ',newtonIter,
248       &        ' / ', SEAICEnewtonIterMax*(myIter-nIter0)+newtonIter,       &        ' / ', totalNewtonItersLoc,
249       &        ', Nb. of FGMRES iterations = ', krylovIter       &        ', Nb. of FGMRES iterations = ', krylovIter
250           CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,           CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
251       &        SQUEEZE_RIGHT, myThid )       &        SQUEEZE_RIGHT, myThid )
252             _END_MASTER( myThid )
253          ENDIF          ENDIF
254          IF ( krylovIter.EQ.SEAICEkrylovIterMax ) THEN          IF ( krylovIter.EQ.SEAICEkrylovIterMax ) THEN
255           krylovIterFail = krylovIterFail + 1           krylovFails = krylovFails + 1
256          ENDIF          ENDIF
257  C     Update linear solution vector and return to Newton iteration  C     Update linear solution vector and return to Newton iteration
258          DO bj=myByLo(myThid),myByHi(myThid)          DO bj=myByLo(myThid),myByHi(myThid)
# Line 262  C     Update linear solution vector and Line 261  C     Update linear solution vector and
261             DO I=1-Olx,sNx+Olx             DO I=1-Olx,sNx+Olx
262              uIce(I,J,bi,bj) = uIce(I,J,bi,bj)+duIce(I,J,bi,bj)              uIce(I,J,bi,bj) = uIce(I,J,bi,bj)+duIce(I,J,bi,bj)
263              vIce(I,J,bi,bj) = vIce(I,J,bi,bj)+dvIce(I,J,bi,bj)              vIce(I,J,bi,bj) = vIce(I,J,bi,bj)+dvIce(I,J,bi,bj)
264    C     reset du/vIce here instead of setting sol = 0 in seaice_fgmres_driver
265                duIce(I,J,bi,bj)= 0. _d 0
266                dvIce(I,J,bi,bj)= 0. _d 0
267             ENDDO             ENDDO
268            ENDDO            ENDDO
269           ENDDO           ENDDO
# Line 271  C     Set the stopping criterion for the Line 273  C     Set the stopping criterion for the
273         ENDIF         ENDIF
274  C     end of Newton iterate  C     end of Newton iterate
275        ENDDO        ENDDO
276  C     some output diagnostics  C
277        IF ( debugLevel.GE.debLevA ) THEN  C--   Output diagnostics
278    C
279          IF ( SEAICE_monFreq .GT. 0. _d 0 ) THEN
280    C     Count iterations
281           totalJFNKtimeSteps = totalJFNKtimeSteps + 1
282           totalNewtonIters   = totalNewtonIters + newtonIter
283           totalKrylovIters   = totalKrylovIters + totalKrylovItersLoc
284  C     Record failure  C     Record failure
285           totalKrylovFails   = totalKrylovFails + krylovFails
286         IF ( newtonIter .EQ. SEAICEnewtonIterMax ) THEN         IF ( newtonIter .EQ. SEAICEnewtonIterMax ) THEN
287          newtonIterFail = newtonIterFail + 1          totalNewtonFails = totalNewtonFails + 1
288           ENDIF
289          ENDIF
290    C     Decide whether it is time to dump and reset the counter
291          writeNow = DIFFERENT_MULTIPLE(SEAICE_monFreq,
292         &     myTime+deltaTClock, deltaTClock)
293    #ifdef ALLOW_CAL
294          IF ( useCAL ) THEN
295           CALL CAL_TIME2DUMP(
296         I      zeroRL, SEAICE_monFreq,  deltaTClock,
297         U      writeNow,
298         I      myTime+deltaTclock, myIter+1, myThid )
299          ENDIF
300    #endif
301          IF ( writeNow ) THEN
302           _BEGIN_MASTER( myThid )
303           WRITE(msgBuf,'(A)')
304         &' // ======================================================='
305           CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
306         &      SQUEEZE_RIGHT, myThid )
307           WRITE(msgBuf,'(A)') ' // Begin JFNK statistics'
308           CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
309         &      SQUEEZE_RIGHT, myThid )
310           WRITE(msgBuf,'(A)')
311         &' // ======================================================='
312           CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
313         &      SQUEEZE_RIGHT, myThid )
314           WRITE(msgBuf,'(A,I10)')
315         &      ' %JFNK_MON: time step              = ', myIter+1
316           CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
317         &      SQUEEZE_RIGHT, myThid )
318           WRITE(msgBuf,'(A,I10)')
319         &      ' %JFNK_MON: Nb. of time steps      = ', totalJFNKtimeSteps
320           CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
321         &      SQUEEZE_RIGHT, myThid )
322           WRITE(msgBuf,'(A,I10)')
323         &      ' %JFNK_MON: Nb. of Newton steps    = ', totalNewtonIters
324           CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
325         &      SQUEEZE_RIGHT, myThid )
326           WRITE(msgBuf,'(A,I10)')
327         &      ' %JFNK_MON: Nb. of Krylov steps    = ', totalKrylovIters
328           CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
329         &      SQUEEZE_RIGHT, myThid )
330           WRITE(msgBuf,'(A,I10)')
331         &      ' %JFNK_MON: Nb. of Newton failures = ', totalNewtonFails
332           CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
333         &      SQUEEZE_RIGHT, myThid )
334           WRITE(msgBuf,'(A,I10)')
335         &      ' %JFNK_MON: Nb. of Krylov failures = ', totalKrylovFails
336           CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
337         &      SQUEEZE_RIGHT, myThid )
338           WRITE(msgBuf,'(A)')
339         &' // ======================================================='
340           CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
341         &      SQUEEZE_RIGHT, myThid )
342           WRITE(msgBuf,'(A)') ' // End JFNK statistics'
343           CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
344         &      SQUEEZE_RIGHT, myThid )
345           WRITE(msgBuf,'(A)')
346         &' // ======================================================='
347           CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
348         &      SQUEEZE_RIGHT, myThid )
349           _END_MASTER( myThid )
350    C     reset and start again
351           totalJFNKtimeSteps = 0
352           totalNewtonIters   = 0
353           totalKrylovIters   = 0
354           totalKrylovFails   = 0
355           totalNewtonFails   = 0
356          ENDIF
357    
358    C     Print more debugging information
359          IF ( debugLevel.GE.debLevA ) THEN
360           IF ( newtonIter .EQ. SEAICEnewtonIterMax ) THEN
361            _BEGIN_MASTER( myThid )
362          WRITE(msgBuf,'(A,I10)')          WRITE(msgBuf,'(A,I10)')
363       &       ' S/R SEAICE_JFNK: JFNK did not converge in timestep ',       &       ' S/R SEAICE_JFNK: JFNK did not converge in timestep ',
364       &       myIter       &       myIter+1
365          CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,          CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
366       &       SQUEEZE_RIGHT, myThid )       &       SQUEEZE_RIGHT, myThid )
367            _END_MASTER( myThid )
368         ENDIF         ENDIF
369         IF ( krylovIterFail .GT. 0 ) THEN         IF ( krylovFails .GT. 0 ) THEN
370            _BEGIN_MASTER( myThid )
371          WRITE(msgBuf,'(A,I4,A,I10)')          WRITE(msgBuf,'(A,I4,A,I10)')
372       &       ' S/R SEAICE_JFNK: FGMRES did not converge ',       &       ' S/R SEAICE_JFNK: FGMRES did not converge ',
373       &       krylovIterFail, ' times in timestep ', myIter       &       krylovFails, ' times in timestep ', myIter+1
374          CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,          CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
375       &       SQUEEZE_RIGHT, myThid )       &       SQUEEZE_RIGHT, myThid )
376            _END_MASTER( myThid )
377         ENDIF         ENDIF
378         WRITE(msgBuf,'(A,I6)')         _BEGIN_MASTER( myThid )
379           WRITE(msgBuf,'(A,I6,A,I10)')
380       &      ' S/R SEAICE_JFNK: Total number FGMRES iterations = ',       &      ' S/R SEAICE_JFNK: Total number FGMRES iterations = ',
381       &      totalKrylovIter       &      totalKrylovItersLoc, ' in timestep ', myIter+1
382          CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
383       &       SQUEEZE_RIGHT, myThid )       &      SQUEEZE_RIGHT, myThid )
384                 _END_MASTER( myThid )
385        ENDIF        ENDIF
386    
387  #endif /* SEAICE_ALLOW_DYNAMICS and SEAICE_CGRID and SEAICE_ALLOW_JFNK */  #endif /* SEAICE_ALLOW_DYNAMICS and SEAICE_CGRID and SEAICE_ALLOW_JFNK */

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.13

  ViewVC Help
Powered by ViewVC 1.1.22