/[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.15 by mlosch, Wed Jan 16 21:20:28 2013 UTC revision 1.22 by mlosch, Tue Apr 23 08:40:06 2013 UTC
# Line 53  C     myThid :: my Thread Id. number Line 53  C     myThid :: my Thread Id. number
53        INTEGER myIter        INTEGER myIter
54        INTEGER myThid        INTEGER myThid
55    
56  #if ( (defined SEAICE_CGRID) && \  #ifdef SEAICE_ALLOW_JFNK
       (defined SEAICE_ALLOW_JFNK) && \  
       (defined SEAICE_ALLOW_DYNAMICS) )  
57  C     !FUNCTIONS:  C     !FUNCTIONS:
58        LOGICAL  DIFFERENT_MULTIPLE        LOGICAL  DIFFERENT_MULTIPLE
59        EXTERNAL DIFFERENT_MULTIPLE        EXTERNAL DIFFERENT_MULTIPLE
60    
61    C     !LOCAL VARIABLES:
62    C     === Local variables ===
63  C     i,j,bi,bj :: loop indices  C     i,j,bi,bj :: loop indices
64        INTEGER i,j,bi,bj        INTEGER i,j,bi,bj
65  C     loop indices  C     loop indices
# Line 73  C     FGMRES flag that indicates what fg Line 73  C     FGMRES flag that indicates what fg
73        _RL     JFNKresidual        _RL     JFNKresidual
74        _RL     JFNKresidualKm1        _RL     JFNKresidualKm1
75  C     parameters to compute convergence criterion  C     parameters to compute convergence criterion
76        _RL     phi_e, alp_e, JFNKgamma_lin        _RL     JFNKgamma_lin
77        _RL     FGMRESeps        _RL     FGMRESeps
78        _RL     JFNKtol        _RL     JFNKtol
79  C      
80        _RL     recip_deltaT        _RL     recip_deltaT
81        LOGICAL JFNKconverged, krylovConverged        LOGICAL JFNKconverged, krylovConverged
82        LOGICAL writeNow        LOGICAL writeNow
83        CHARACTER*(MAX_LEN_MBUF) msgBuf        CHARACTER*(MAX_LEN_MBUF) msgBuf
84  C  
85  C     u/vIceRes :: residual of sea-ice momentum equations  C     u/vIceRes :: residual of sea-ice momentum equations
86        _RL uIceRes(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)        _RL uIceRes(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
87        _RL vIceRes(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)        _RL vIceRes(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
 C     vector version of the residuals  
       _RL resTmp (nVec,1,nSx,nSy)  
88  C     du/vIce   :: ice velocity increment to be added to u/vIce  C     du/vIce   :: ice velocity increment to be added to u/vIce
89        _RL duIce  (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)        _RL duIce  (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
90        _RL dvIce  (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)        _RL dvIce  (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
91  C     precomputed (= constant per Newton iteration) versions of  C     precomputed (= constant per Newton iteration) versions of
92  C     zeta, eta, and DWATN, press  C     zeta, eta, and DWATN, press
93        _RL zetaPre (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)        _RL zetaPre (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
94        _RL etaPre  (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)        _RL etaPre  (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
# Line 115  C     with iOutFgmres=1, seaice_fgmres p Line 113  C     with iOutFgmres=1, seaice_fgmres p
113       &     DIFFERENT_MULTIPLE( SEAICE_monFreq, myTime, deltaTClock ) )       &     DIFFERENT_MULTIPLE( SEAICE_monFreq, myTime, deltaTClock ) )
114       &     iOutFGMRES=1       &     iOutFGMRES=1
115    
 C      
116        DO bj=myByLo(myThid),myByHi(myThid)        DO bj=myByLo(myThid),myByHi(myThid)
117         DO bi=myBxLo(myThid),myBxHi(myThid)         DO bi=myBxLo(myThid),myBxHi(myThid)
118          DO J=1-Oly,sNy+Oly          DO J=1-OLy,sNy+OLy
119           DO I=1-Olx,sNx+Olx           DO I=1-OLx,sNx+OLx
120            uIceRes(I,J,bi,bj) = 0. _d 0            uIceRes(I,J,bi,bj) = 0. _d 0
121            vIceRes(I,J,bi,bj) = 0. _d 0            vIceRes(I,J,bi,bj) = 0. _d 0
122            duIce  (I,J,bi,bj) = 0. _d 0            duIce  (I,J,bi,bj) = 0. _d 0
# Line 129  C Line 126  C
126           ENDDO           ENDDO
127          ENDDO          ENDDO
128  C     Compute things that do no change during the Newton iteration:  C     Compute things that do no change during the Newton iteration:
129  C     sea-surface tilt and wind stress:  C     sea-surface tilt and wind stress:
130  C     FORCEX/Y0 - mass*(u/vIceNm1)/deltaT  C     FORCEX/Y0 - mass*(u/vIceNm1)/deltaT
131          DO J=1-Oly,sNy+Oly          DO J=1-OLy,sNy+OLy
132           DO I=1-Olx,sNx+Olx           DO I=1-OLx,sNx+OLx
133            FORCEX(I,J,bi,bj) = FORCEX0(I,J,bi,bj)            FORCEX(I,J,bi,bj) = FORCEX0(I,J,bi,bj)
134       &         + seaiceMassU(I,J,bi,bj)*uIceNm1(I,J,bi,bj)*recip_deltaT           &         + seaiceMassU(I,J,bi,bj)*uIceNm1(I,J,bi,bj)*recip_deltaT
135            FORCEY(I,J,bi,bj) = FORCEY0(I,J,bi,bj)            FORCEY(I,J,bi,bj) = FORCEY0(I,J,bi,bj)
136       &         + seaiceMassV(I,J,bi,bj)*vIceNm1(I,J,bi,bj)*recip_deltaT           &         + seaiceMassV(I,J,bi,bj)*vIceNm1(I,J,bi,bj)*recip_deltaT
137           ENDDO           ENDDO
138          ENDDO          ENDDO
139         ENDDO         ENDDO
# Line 147  C     Start nonlinear Newton iteration: Line 144  C     Start nonlinear Newton iteration:
144         newtonIter = newtonIter + 1         newtonIter = newtonIter + 1
145  C     Compute initial residual F(u), (includes computation of global  C     Compute initial residual F(u), (includes computation of global
146  C     variables DWATN, zeta, and eta)  C     variables DWATN, zeta, and eta)
147  C     Update linear solution vector and return to Newton iteration         IF ( newtonIter .EQ. 1 ) CALL SEAICE_JFNK_UPDATE(
148  C     Do the linesearch       I      duIce, dvIce,
        CALL SEAICE_JFNK_UPDATE(  
      I      duIce, dvIce,  
149       U      uIce, vIce, JFNKresidual,       U      uIce, vIce, JFNKresidual,
150       O      uIceRes, vIceRes,       O      uIceRes, vIceRes,
151       I      newtonIter, myTime, myIter, myThid )       I      newtonIter, myTime, myIter, myThid )
 C     reset du/vIce here instead of setting sol = 0 in seaice_fgmres_driver  
        DO bj=myByLo(myThid),myByHi(myThid)  
         DO bi=myBxLo(myThid),myBxHi(myThid)  
          DO J=1-Oly,sNy+Oly  
           DO I=1-Olx,sNx+Olx  
            duIce(I,J,bi,bj)= 0. _d 0  
            dvIce(I,J,bi,bj)= 0. _d 0  
           ENDDO  
          ENDDO  
         ENDDO  
        ENDDO  
 CMLC     Do it again, Sam  
 CML       CALL SEAICE_CALC_RESIDUAL(  
 CML     I      uIce, vIce,  
 CML     O      uIceRes, vIceRes,  
 CML     I      newtonIter, 0, myTime, myIter, myThid )  
 CMLC     probably not necessary, will be removed later:  
 CML       CALL EXCH_UV_XY_RL( uIceRes, vIceRes,.TRUE.,myThid)  
 CMLC     Important: Compute the norm of the residual using the same scalar  
 CMLC     product that SEAICE_FGMRES does  
 CML       CALL SEAICE_MAP2VEC(nVec,uIceRes,vIceRes,resTmp,.TRUE.,myThid)  
 CML       CALL SEAICE_SCALPROD(  
 CML     &      nVec,1,1,1,resTmp,resTmp,JFNKresidual,myThid)  
 CML       JFNKresidual = SQRT(JFNKresidual)  
152  C     local copies of precomputed coefficients that are to stay  C     local copies of precomputed coefficients that are to stay
153  C     constant for the preconditioner  C     constant for the preconditioner
154         DO bj=myByLo(myThid),myByHi(myThid)         DO bj=myByLo(myThid),myByHi(myThid)
155          DO bi=myBxLo(myThid),myBxHi(myThid)          DO bi=myBxLo(myThid),myBxHi(myThid)
156           DO j=1-Oly,sNy+Oly           DO j=1-OLy,sNy+OLy
157            DO i=1-Olx,sNx+Olx            DO i=1-OLx,sNx+OLx
158             zetaPre(I,J,bi,bj) =  zeta(I,J,bi,bj)             zetaPre(I,J,bi,bj) =  zeta(I,J,bi,bj)
159              etaPre(I,J,bi,bj) =   eta(I,J,bi,bj)              etaPre(I,J,bi,bj) =   eta(I,J,bi,bj)
160             etaZPre(I,J,bi,bj) =  etaZ(I,J,bi,bj)             etaZPre(I,J,bi,bj) =  etaZ(I,J,bi,bj)
# Line 194  C     constant for the preconditioner Line 165  C     constant for the preconditioner
165         ENDDO         ENDDO
166  C     compute convergence criterion for linear preconditioned FGMRES  C     compute convergence criterion for linear preconditioned FGMRES
167         JFNKgamma_lin = JFNKgamma_lin_max         JFNKgamma_lin = JFNKgamma_lin_max
168         IF ( newtonIter.GT.1.AND.newtonIter.LE.100         IF ( newtonIter.GT.1.AND.newtonIter.LE.SEAICE_JFNK_tolIter
169       &      .AND.JFNKresidual.LT.JFNKres_t ) THEN       &      .AND.JFNKresidual.LT.JFNKres_t ) THEN
170  C     Eisenstat, 1996, equ.(2.6)        C     Eisenstat and Walker (1996), eq.(2.6)
171          phi_e = 1. _d 0          JFNKgamma_lin = SEAICE_JFNKphi
172          alp_e = 1. _d 0       &       *( JFNKresidual/JFNKresidualKm1 )**SEAICE_JFNKalpha
         JFNKgamma_lin = phi_e*( JFNKresidual/JFNKresidualKm1 )**alp_e  
173          JFNKgamma_lin = min(JFNKgamma_lin_max, JFNKgamma_lin)          JFNKgamma_lin = min(JFNKgamma_lin_max, JFNKgamma_lin)
174          JFNKgamma_lin = max(JFNKgamma_lin_min, JFNKgamma_lin)          JFNKgamma_lin = max(JFNKgamma_lin_min, JFNKgamma_lin)
175         ENDIF         ENDIF
176  C     save the residual for the next iteration  C     save the residual for the next iteration
177         JFNKresidualKm1 = JFNKresidual         JFNKresidualKm1 = JFNKresidual
178  C  
179  C     The Krylov iteration using FGMRES, the preconditioner is LSOR  C     The Krylov iteration using FGMRES, the preconditioner is LSOR
180  C     for now. The code is adapted from SEAICE_LSR, but heavily stripped  C     for now. The code is adapted from SEAICE_LSR, but heavily stripped
181  C     down.  C     down.
# Line 213  C     krylovIter is mapped into "its" in Line 183  C     krylovIter is mapped into "its" in
183  C     in that routine  C     in that routine
184         krylovIter    = 0         krylovIter    = 0
185         iCode         = 0         iCode         = 0
186  C  
187         JFNKconverged = JFNKresidual.LT.JFNKtol         JFNKconverged = JFNKresidual.LT.JFNKtol
188  C  
189  C     do Krylov loop only if convergence is not reached  C     do Krylov loop only if convergence is not reached
190  C  
191         IF ( .NOT.JFNKconverged ) THEN         IF ( .NOT.JFNKconverged ) THEN
192  C  
193  C     start Krylov iteration (FGMRES)  C     start Krylov iteration (FGMRES)
194  C  
195          krylovConverged = .FALSE.          krylovConverged = .FALSE.
196          FGMRESeps = JFNKgamma_lin * JFNKresidual          FGMRESeps = JFNKgamma_lin * JFNKresidual
197          DO WHILE ( .NOT.krylovConverged )          DO WHILE ( .NOT.krylovConverged )
198  C     solution vector sol = du/vIce  C     solution vector sol = du/vIce
199  C     residual vector (rhs) Fu = u/vIceRes  C     residual vector (rhs) Fu = u/vIceRes
200  C     output work vectors wk1, -> input work vector wk2  C     output work vectors wk1, -> input work vector wk2
201  C      
202           CALL SEAICE_FGMRES_DRIVER(           CALL SEAICE_FGMRES_DRIVER(
203       I        uIceRes, vIceRes,       I        uIceRes, vIceRes,
204       U        duIce, dvIce, iCode,       U        duIce, dvIce, iCode,
205       I        FGMRESeps, iOutFGMRES,       I        FGMRESeps, iOutFGMRES,
206       I        newtonIter, krylovIter, myTime, myIter, myThid )       I        newtonIter, krylovIter, myTime, myIter, myThid )
# Line 238  C     FGMRES returns iCode either asking Line 208  C     FGMRES returns iCode either asking
208  C     or product of matrix (Jacobian) times vector. For iCode = 0, terminate  C     or product of matrix (Jacobian) times vector. For iCode = 0, terminate
209  C     iteration  C     iteration
210           IF (iCode.EQ.1) THEN           IF (iCode.EQ.1) THEN
211  C     Call preconditioner  C     Call preconditioner
212            IF ( SOLV_MAX_ITERS .GT. 0 )            IF ( SOLV_MAX_ITERS .GT. 0 )
213       &         CALL SEAICE_PRECONDITIONER(       &         CALL SEAICE_PRECONDITIONER(
214       U         duIce, dvIce,       U         duIce, dvIce,
215       I         zetaPre, etaPre, etaZpre, dwatPre,       I         zetaPre, etaPre, etaZpre, dwatPre,
216       I         newtonIter, krylovIter, myTime, myIter, myThid )       I         newtonIter, krylovIter, myTime, myIter, myThid )
217           ELSEIF (iCode.GE.2) THEN           ELSEIF (iCode.GE.2) THEN
218  C     Compute Jacobian times vector  C     Compute Jacobian times vector
219            CALL SEAICE_JACVEC(            CALL SEAICE_JACVEC(
220       I         uIce, vIce, uIceRes, vIceRes,       I         uIce, vIce, uIceRes, vIceRes,
221       U         duIce, dvIce,         U         duIce, dvIce,
222       I         newtonIter, krylovIter, myTime, myIter, myThid )       I         newtonIter, krylovIter, myTime, myIter, myThid )
223           ENDIF           ENDIF
224           krylovConverged = iCode.EQ.0           krylovConverged = iCode.EQ.0
# Line 258  C     End of Krylov iterate Line 228  C     End of Krylov iterate
228  C     some output diagnostics  C     some output diagnostics
229          IF ( debugLevel.GE.debLevA ) THEN          IF ( debugLevel.GE.debLevA ) THEN
230           _BEGIN_MASTER( myThid )           _BEGIN_MASTER( myThid )
231           totalNewtonItersLoc =           totalNewtonItersLoc =
232       &        SEAICEnewtonIterMax*(myIter-nIter0)+newtonIter       &        SEAICEnewtonIterMax*(myIter-nIter0)+newtonIter
233           WRITE(msgBuf,'(2A,2(1XI6),2E12.5)')           WRITE(msgBuf,'(2A,2(1XI6),2E12.5)')
234       &        ' S/R SEAICE_JFNK: Newton iterate / total, ',       &        ' S/R SEAICE_JFNK: Newton iterate / total, ',
235       &        'JFNKgamma_lin, initial norm = ',       &        'JFNKgamma_lin, initial norm = ',
236       &        newtonIter, totalNewtonItersLoc,       &        newtonIter, totalNewtonItersLoc,
# Line 268  C     some output diagnostics Line 238  C     some output diagnostics
238           CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,           CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
239       &        SQUEEZE_RIGHT, myThid )       &        SQUEEZE_RIGHT, myThid )
240           WRITE(msgBuf,'(3(A,I6))')           WRITE(msgBuf,'(3(A,I6))')
241       &        ' S/R SEAICE_JFNK: Newton iterate / total = ',newtonIter,       &        ' S/R SEAICE_JFNK: Newton iterate / total = ',newtonIter,
242       &        ' / ', totalNewtonItersLoc,       &        ' / ', totalNewtonItersLoc,
243       &        ', Nb. of FGMRES iterations = ', krylovIter       &        ', Nb. of FGMRES iterations = ', krylovIter
244           CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,           CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
# Line 278  C     some output diagnostics Line 248  C     some output diagnostics
248          IF ( krylovIter.EQ.SEAICEkrylovIterMax ) THEN          IF ( krylovIter.EQ.SEAICEkrylovIterMax ) THEN
249           krylovFails = krylovFails + 1           krylovFails = krylovFails + 1
250          ENDIF          ENDIF
251  C     Set the stopping criterion for the Newton iteration  C     Set the stopping criterion for the Newton iteration and the
252          IF ( newtonIter .EQ. 1 ) JFNKtol=JFNKgamma_nonlin*JFNKresidual  C     criterion for the transition from accurate to approximate FGMRES
253            IF ( newtonIter .EQ. 1 ) THEN
254             JFNKtol=JFNKgamma_nonlin*JFNKresidual
255             IF ( JFNKres_tFac .NE. UNSET_RL )
256         &        JFNKres_t = JFNKresidual * JFNKres_tFac
257            ENDIF
258  C     Update linear solution vector and return to Newton iteration  C     Update linear solution vector and return to Newton iteration
259  C     Do a linesearch if necessary, and compute a new residual.  C     Do a linesearch if necessary, and compute a new residual.
260  C     Note that it should be possible to do the following operations  C     Note that it should be possible to do the following operations
261  C     at the beginning of the Newton iteration, thereby saving us from  C     at the beginning of the Newton iteration, thereby saving us from
262  C     the extra call of seaice_jfnk_update, but unfortunately that  C     the extra call of seaice_jfnk_update, but unfortunately that
263  C     changes the results, so we leave the stuff here for now.  C     changes the results, so we leave the stuff here for now.
264          CALL SEAICE_JFNK_UPDATE(          CALL SEAICE_JFNK_UPDATE(
265       I       duIce, dvIce,       I       duIce, dvIce,
266       U       uIce, vIce, JFNKresidual,       U       uIce, vIce, JFNKresidual,
267       O       uIceRes, vIceRes,       O       uIceRes, vIceRes,
268       I       newtonIter, myTime, myIter, myThid )       I       newtonIter, myTime, myIter, myThid )
269  C     reset du/vIce here instead of setting sol = 0 in seaice_fgmres_driver  C     reset du/vIce here instead of setting sol = 0 in seaice_fgmres_driver
270          DO bj=myByLo(myThid),myByHi(myThid)          DO bj=myByLo(myThid),myByHi(myThid)
271           DO bi=myBxLo(myThid),myBxHi(myThid)           DO bi=myBxLo(myThid),myBxHi(myThid)
272            DO J=1-Oly,sNy+Oly            DO J=1-OLy,sNy+OLy
273             DO I=1-Olx,sNx+Olx             DO I=1-OLx,sNx+OLx
274              duIce(I,J,bi,bj)= 0. _d 0              duIce(I,J,bi,bj)= 0. _d 0
275              dvIce(I,J,bi,bj)= 0. _d 0              dvIce(I,J,bi,bj)= 0. _d 0
276             ENDDO             ENDDO
# Line 305  C     reset du/vIce here instead of sett Line 280  C     reset du/vIce here instead of sett
280         ENDIF         ENDIF
281  C     end of Newton iterate  C     end of Newton iterate
282        ENDDO        ENDDO
283  C  
284  C--   Output diagnostics  C--   Output diagnostics
285  C  
286        IF ( SEAICE_monFreq .GT. 0. _d 0 ) THEN        IF ( SEAICE_monFreq .GT. 0. _d 0 ) THEN
287  C     Count iterations  C     Count iterations
288         totalJFNKtimeSteps = totalJFNKtimeSteps + 1         totalJFNKtimeSteps = totalJFNKtimeSteps + 1
# Line 316  C     Count iterations Line 291  C     Count iterations
291  C     Record failure  C     Record failure
292         totalKrylovFails   = totalKrylovFails + krylovFails         totalKrylovFails   = totalKrylovFails + krylovFails
293         IF ( newtonIter .EQ. SEAICEnewtonIterMax ) THEN         IF ( newtonIter .EQ. SEAICEnewtonIterMax ) THEN
294          totalNewtonFails = totalNewtonFails + 1          totalNewtonFails = totalNewtonFails + 1
295         ENDIF         ENDIF
296        ENDIF        ENDIF
297  C     Decide whether it is time to dump and reset the counter  C     Decide whether it is time to dump and reset the counter
298        writeNow = DIFFERENT_MULTIPLE(SEAICE_monFreq,        writeNow = DIFFERENT_MULTIPLE(SEAICE_monFreq,
299       &     myTime+deltaTClock, deltaTClock)       &     myTime+deltaTClock, deltaTClock)
300  #ifdef ALLOW_CAL  #ifdef ALLOW_CAL
301        IF ( useCAL ) THEN        IF ( useCAL ) THEN
302         CALL CAL_TIME2DUMP(         CALL CAL_TIME2DUMP(
303       I      zeroRL, SEAICE_monFreq,  deltaTClock,       I      zeroRL, SEAICE_monFreq,  deltaTClock,
304       U      writeNow,       U      writeNow,
305       I      myTime+deltaTclock, myIter+1, myThid )       I      myTime+deltaTclock, myIter+1, myThid )
# Line 332  C     Decide whether it is time to dump Line 307  C     Decide whether it is time to dump
307  #endif  #endif
308        IF ( writeNow ) THEN        IF ( writeNow ) THEN
309         _BEGIN_MASTER( myThid )         _BEGIN_MASTER( myThid )
310         WRITE(msgBuf,'(A)')         WRITE(msgBuf,'(A)')
311       &' // ======================================================='       &' // ======================================================='
312         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
313       &      SQUEEZE_RIGHT, myThid )       &      SQUEEZE_RIGHT, myThid )
314         WRITE(msgBuf,'(A)') ' // Begin JFNK statistics'         WRITE(msgBuf,'(A)') ' // Begin JFNK statistics'
315         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
316       &      SQUEEZE_RIGHT, myThid )       &      SQUEEZE_RIGHT, myThid )
317         WRITE(msgBuf,'(A)')         WRITE(msgBuf,'(A)')
318       &' // ======================================================='       &' // ======================================================='
319         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
320       &      SQUEEZE_RIGHT, myThid )       &      SQUEEZE_RIGHT, myThid )
321         WRITE(msgBuf,'(A,I10)')         WRITE(msgBuf,'(A,I10)')
322       &      ' %JFNK_MON: time step              = ', myIter+1       &      ' %JFNK_MON: time step              = ', myIter+1
323         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
324       &      SQUEEZE_RIGHT, myThid )       &      SQUEEZE_RIGHT, myThid )
325         WRITE(msgBuf,'(A,I10)')         WRITE(msgBuf,'(A,I10)')
326       &      ' %JFNK_MON: Nb. of time steps      = ', totalJFNKtimeSteps       &      ' %JFNK_MON: Nb. of time steps      = ', totalJFNKtimeSteps
327         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
328       &      SQUEEZE_RIGHT, myThid )       &      SQUEEZE_RIGHT, myThid )
329         WRITE(msgBuf,'(A,I10)')         WRITE(msgBuf,'(A,I10)')
330       &      ' %JFNK_MON: Nb. of Newton steps    = ', totalNewtonIters       &      ' %JFNK_MON: Nb. of Newton steps    = ', totalNewtonIters
331         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
332       &      SQUEEZE_RIGHT, myThid )       &      SQUEEZE_RIGHT, myThid )
333         WRITE(msgBuf,'(A,I10)')         WRITE(msgBuf,'(A,I10)')
334       &      ' %JFNK_MON: Nb. of Krylov steps    = ', totalKrylovIters       &      ' %JFNK_MON: Nb. of Krylov steps    = ', totalKrylovIters
335         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
336       &      SQUEEZE_RIGHT, myThid )       &      SQUEEZE_RIGHT, myThid )
337         WRITE(msgBuf,'(A,I10)')         WRITE(msgBuf,'(A,I10)')
338       &      ' %JFNK_MON: Nb. of Newton failures = ', totalNewtonFails       &      ' %JFNK_MON: Nb. of Newton failures = ', totalNewtonFails
339         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
340       &      SQUEEZE_RIGHT, myThid )       &      SQUEEZE_RIGHT, myThid )
341         WRITE(msgBuf,'(A,I10)')         WRITE(msgBuf,'(A,I10)')
342       &      ' %JFNK_MON: Nb. of Krylov failures = ', totalKrylovFails       &      ' %JFNK_MON: Nb. of Krylov failures = ', totalKrylovFails
343         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
344       &      SQUEEZE_RIGHT, myThid )       &      SQUEEZE_RIGHT, myThid )
345         WRITE(msgBuf,'(A)')         WRITE(msgBuf,'(A)')
346       &' // ======================================================='       &' // ======================================================='
347         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
348       &      SQUEEZE_RIGHT, myThid )       &      SQUEEZE_RIGHT, myThid )
349         WRITE(msgBuf,'(A)') ' // End JFNK statistics'         WRITE(msgBuf,'(A)') ' // End JFNK statistics'
350         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
351       &      SQUEEZE_RIGHT, myThid )       &      SQUEEZE_RIGHT, myThid )
352         WRITE(msgBuf,'(A)')         WRITE(msgBuf,'(A)')
353       &' // ======================================================='       &' // ======================================================='
354         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
355       &      SQUEEZE_RIGHT, myThid )       &      SQUEEZE_RIGHT, myThid )
# Line 391  C     Print more debugging information Line 366  C     Print more debugging information
366        IF ( debugLevel.GE.debLevA ) THEN        IF ( debugLevel.GE.debLevA ) THEN
367         IF ( newtonIter .EQ. SEAICEnewtonIterMax ) THEN         IF ( newtonIter .EQ. SEAICEnewtonIterMax ) THEN
368          _BEGIN_MASTER( myThid )          _BEGIN_MASTER( myThid )
369          WRITE(msgBuf,'(A,I10)')          WRITE(msgBuf,'(A,I10)')
370       &       ' S/R SEAICE_JFNK: JFNK did not converge in timestep ',       &       ' S/R SEAICE_JFNK: JFNK did not converge in timestep ',
371       &       myIter+1       &       myIter+1
372          CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,          CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
# Line 400  C     Print more debugging information Line 375  C     Print more debugging information
375         ENDIF         ENDIF
376         IF ( krylovFails .GT. 0 ) THEN         IF ( krylovFails .GT. 0 ) THEN
377          _BEGIN_MASTER( myThid )          _BEGIN_MASTER( myThid )
378          WRITE(msgBuf,'(A,I4,A,I10)')          WRITE(msgBuf,'(A,I4,A,I10)')
379       &       ' S/R SEAICE_JFNK: FGMRES did not converge ',       &       ' S/R SEAICE_JFNK: FGMRES did not converge ',
380       &       krylovFails, ' times in timestep ', myIter+1       &       krylovFails, ' times in timestep ', myIter+1
381          CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,          CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
# Line 408  C     Print more debugging information Line 383  C     Print more debugging information
383          _END_MASTER( myThid )          _END_MASTER( myThid )
384         ENDIF         ENDIF
385         _BEGIN_MASTER( myThid )         _BEGIN_MASTER( myThid )
386         WRITE(msgBuf,'(A,I6,A,I10)')         WRITE(msgBuf,'(A,I6,A,I10)')
387       &      ' S/R SEAICE_JFNK: Total number FGMRES iterations = ',       &      ' S/R SEAICE_JFNK: Total number FGMRES iterations = ',
388       &      totalKrylovItersLoc, ' in timestep ', myIter+1       &      totalKrylovItersLoc, ' in timestep ', myIter+1
389         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
# Line 419  C     Print more debugging information Line 394  C     Print more debugging information
394        RETURN        RETURN
395        END        END
396    
397    C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
398  CBOP  CBOP
399  C     !ROUTINE: SEAICE_JFNK_UPDATE  C     !ROUTINE: SEAICE_JFNK_UPDATE
400  C     !INTERFACE:  C     !INTERFACE:
401    
402        SUBROUTINE SEAICE_JFNK_UPDATE(        SUBROUTINE SEAICE_JFNK_UPDATE(
403       I     duIce, dvIce,       I     duIce, dvIce,
404       U     uIce, vIce, JFNKresidual,       U     uIce, vIce, JFNKresidual,
405       O     uIceRes, vIceRes,       O     uIceRes, vIceRes,
406       I     newtonIter, myTime, myIter, myThid )       I     newtonIter, myTime, myIter, myThid )
# Line 475  C     u/vIceRes :: residual of sea-ice m Line 451  C     u/vIceRes :: residual of sea-ice m
451        _RL uIceRes(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)        _RL uIceRes(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
452        _RL vIceRes(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)        _RL vIceRes(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
453    
454  C     Local variables:  C     !LOCAL VARIABLES:
455    C     === Local variables ===
456  C     i,j,bi,bj :: loop indices  C     i,j,bi,bj :: loop indices
457        INTEGER i,j,bi,bj        INTEGER i,j,bi,bj
458        INTEGER l        INTEGER l
459        _RL     resLoc, facLS        _RL     resLoc, facLS
460        LOGICAL doLineSearch        LOGICAL doLineSearch
461  C     nVec    :: size of the input vector(s)  C     nVec    :: size of the input vector(s)
462  C     vector version of the residuals  C     resTmp  :: vector version of the residuals
463        INTEGER nVec        INTEGER nVec
464        PARAMETER ( nVec  = 2*sNx*sNy )        PARAMETER ( nVec  = 2*sNx*sNy )
465        _RL resTmp (nVec,1,nSx,nSy)        _RL resTmp (nVec,1,nSx,nSy)
466  C  
467        CHARACTER*(MAX_LEN_MBUF) msgBuf        CHARACTER*(MAX_LEN_MBUF) msgBuf
468  CEOP  CEOP
469    
# Line 496  C     Initialise some local variables Line 473  C     Initialise some local variables
473        facLS = 1. _d 0        facLS = 1. _d 0
474        doLineSearch = .TRUE.        doLineSearch = .TRUE.
475        DO WHILE ( doLineSearch )        DO WHILE ( doLineSearch )
 C     Determine, if we need more iterations  
        doLineSearch = resLoc .GE. JFNKresidual  
        doLineSearch = doLineSearch .AND. l .LE. 4  
 C     For the first iteration du/vIce = 0 and there will be no  
 C     improvement of the residual possible, so we do only the first  
 C     iteration  
        IF ( newtonIter .EQ. 1 ) doLineSearch = .FALSE.  
 C     Only start a linesearch after some Newton iterations  
        IF ( newtonIter .LE. SEAICE_JFNK_lsIter ) doLineSearch = .FALSE.  
 C     Increment counter  
        l = l + 1  
476  C     Create update  C     Create update
477         DO bj=myByLo(myThid),myByHi(myThid)         DO bj=myByLo(myThid),myByHi(myThid)
478          DO bi=myBxLo(myThid),myBxHi(myThid)          DO bi=myBxLo(myThid),myBxHi(myThid)
479           DO J=1-Oly,sNy+Oly           DO J=1-OLy,sNy+OLy
480            DO I=1-Olx,sNx+Olx            DO I=1-OLx,sNx+OLx
481             uIce(I,J,bi,bj) = uIce(I,J,bi,bj)+facLS*duIce(I,J,bi,bj)             uIce(I,J,bi,bj) = uIce(I,J,bi,bj)+facLS*duIce(I,J,bi,bj)
482             vIce(I,J,bi,bj) = vIce(I,J,bi,bj)+facLS*dvIce(I,J,bi,bj)             vIce(I,J,bi,bj) = vIce(I,J,bi,bj)+facLS*dvIce(I,J,bi,bj)
483            ENDDO            ENDDO
# Line 520  C     Create update Line 486  C     Create update
486         ENDDO         ENDDO
487  C     Compute current residual F(u), (includes re-computation of global  C     Compute current residual F(u), (includes re-computation of global
488  C     variables DWATN, zeta, and eta, i.e. they are different after this)  C     variables DWATN, zeta, and eta, i.e. they are different after this)
489         CALL SEAICE_CALC_RESIDUAL(         CALL SEAICE_CALC_RESIDUAL(
490       I      uIce, vIce,       I      uIce, vIce,
491       O      uIceRes, vIceRes,       O      uIceRes, vIceRes,
492       I      newtonIter, 0, myTime, myIter, myThid )       I      newtonIter, 0, myTime, myIter, myThid )
493  C     Important: Compute the norm of the residual using the same scalar  C     Important: Compute the norm of the residual using the same scalar
494  C     product that SEAICE_FGMRES does  C     product that SEAICE_FGMRES does
495         CALL SEAICE_MAP2VEC(nVec,uIceRes,vIceRes,resTmp,.TRUE.,myThid)         CALL SEAICE_MAP2VEC(nVec,uIceRes,vIceRes,resTmp,.TRUE.,myThid)
496         CALL SEAICE_SCALPROD(nVec,1,1,1,resTmp,resTmp,resLoc,myThid)         CALL SEAICE_SCALPROD(nVec,1,1,1,resTmp,resTmp,resLoc,myThid)
497         resLoc = SQRT(resLoc)         resLoc = SQRT(resLoc)
498    C     Determine, if we need more iterations
499           doLineSearch = resLoc .GE. JFNKresidual
500    C     Limit the maximum number of iterations arbitrarily to four
501           doLineSearch = doLineSearch .AND. l .LT. 4
502    C     For the first iteration du/vIce = 0 and there will be no
503    C     improvement of the residual possible, so we do only the first
504    C     iteration
505           IF ( newtonIter .EQ. 1 ) doLineSearch = .FALSE.
506    C     Only start a linesearch after some Newton iterations
507           IF ( newtonIter .LE. SEAICE_JFNK_lsIter ) doLineSearch = .FALSE.
508    C     Increment counter
509           l = l + 1
510  C     some output diagnostics  C     some output diagnostics
511         IF ( debugLevel.GE.debLevA .AND. doLineSearch ) THEN         IF ( debugLevel.GE.debLevA .AND. doLineSearch ) THEN
512          _BEGIN_MASTER( myThid )          _BEGIN_MASTER( myThid )
513          WRITE(msgBuf,'(2A,2(1XI6),3E12.5)')          WRITE(msgBuf,'(2A,2(1XI6),3E12.5)')
514       &       ' S/R SEAICE_JFNK_UPDATE: Newton iter, LSiter, ',       &       ' S/R SEAICE_JFNK_UPDATE: Newton iter, LSiter, ',
515       &       'facLS, JFNKresidual, resLoc = ',       &       'facLS, JFNKresidual, resLoc = ',
516       &        newtonIter, l, facLS, JFNKresidual, resLoc       &        newtonIter, l, facLS, JFNKresidual, resLoc
# Line 548  C     iterations, 0.25*du/vIce in the se Line 526  C     iterations, 0.25*du/vIce in the se
526  C     This is the new residual  C     This is the new residual
527        JFNKresidual = resLoc        JFNKresidual = resLoc
528    
529  #endif /* SEAICE_ALLOW_DYNAMICS and SEAICE_CGRID and SEAICE_ALLOW_JFNK */  #endif /* SEAICE_ALLOW_JFNK */
530    
531        RETURN        RETURN
532        END        END

Legend:
Removed from v.1.15  
changed lines
  Added in v.1.22

  ViewVC Help
Powered by ViewVC 1.1.22