/[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.6 by mlosch, Wed Nov 7 10:08:25 2012 UTC revision 1.28 by mlosch, Mon Dec 1 12:31:36 2014 UTC
# Line 2  C $Header$ Line 2  C $Header$
2  C $Name$  C $Name$
3    
4  #include "SEAICE_OPTIONS.h"  #include "SEAICE_OPTIONS.h"
5    #ifdef ALLOW_AUTODIFF
6    # include "AUTODIFF_OPTIONS.h"
7    #endif
8    
9    C--  File seaice_jfnk.F: seaice jfnk dynamical solver S/R:
10    C--   Contents
11    C--   o SEAICE_JFNK
12    C--   o SEAICE_JFNK_UPDATE
13    
14  CBOP  CBOP
15  C     !ROUTINE: SEAICE_JFNK  C     !ROUTINE: SEAICE_JFNK
# Line 10  C     !INTERFACE: Line 18  C     !INTERFACE:
18    
19  C     !DESCRIPTION: \bv  C     !DESCRIPTION: \bv
20  C     *==========================================================*  C     *==========================================================*
21  C     | SUBROUTINE SEAICE_JFKF  C     | SUBROUTINE SEAICE_JFNK
22  C     | o Ice dynamics using a Jacobian-free Newton-Krylov solver  C     | o Ice dynamics using a Jacobian-free Newton-Krylov solver
23  C     |   following J.-F. Lemieux et al. Improving the numerical  C     |   following J.-F. Lemieux et al. Improving the numerical
24  C     |   convergence of viscous-plastic sea ice models with the  C     |   convergence of viscous-plastic sea ice models with the
# Line 48  C     myThid :: my Thread Id. number Line 56  C     myThid :: my Thread Id. number
56        INTEGER myIter        INTEGER myIter
57        INTEGER myThid        INTEGER myThid
58    
59  #if ( (defined SEAICE_CGRID) && \  #ifdef SEAICE_ALLOW_JFNK
       (defined SEAICE_ALLOW_JFNK) && \  
       (defined SEAICE_ALLOW_DYNAMICS) )  
60  C     !FUNCTIONS:  C     !FUNCTIONS:
61        LOGICAL  DIFFERENT_MULTIPLE        LOGICAL  DIFFERENT_MULTIPLE
62        EXTERNAL DIFFERENT_MULTIPLE        EXTERNAL DIFFERENT_MULTIPLE
63    
64    C     !LOCAL VARIABLES:
65    C     === Local variables ===
66  C     i,j,bi,bj :: loop indices  C     i,j,bi,bj :: loop indices
67        INTEGER i,j,bi,bj        INTEGER i,j,bi,bj
68  C     loop indices  C     loop indices
69        INTEGER newtonIter        INTEGER newtonIter
70        INTEGER krylovIter, krylovFails        INTEGER krylovIter, krylovFails
71        INTEGER totalKrylovItersLoc        INTEGER totalKrylovItersLoc, totalNewtonItersLoc
72  C     FGMRES flag that determines amount of output messages of fgmres  C     FGMRES flag that determines amount of output messages of fgmres
73        INTEGER iOutFGMRES        INTEGER iOutFGMRES
74  C     FGMRES flag that indicates what fgmres wants us to do next  C     FGMRES flag that indicates what fgmres wants us to do next
75        INTEGER iCode        INTEGER iCode
76        _RL     JFNKresidual, JFNKresidualTile(nSx,nSy)        _RL     JFNKresidual
77        _RL     JFNKresidualKm1        _RL     JFNKresidualKm1
78  C     parameters to compute convergence criterion  C     parameters to compute convergence criterion
79        _RL     phi_e, alp_e, JFNKgamma_lin        _RL     JFNKgamma_lin
80        _RL     FGMRESeps        _RL     FGMRESeps
81        _RL     JFNKtol        _RL     JFNKtol
82  C      C     backward differences extrapolation factors
83          _RL bdfFac, bdfAlpha
84    C
85        _RL     recip_deltaT        _RL     recip_deltaT
86        LOGICAL JFNKconverged, krylovConverged        LOGICAL JFNKconverged, krylovConverged
87          LOGICAL writeNow
88        CHARACTER*(MAX_LEN_MBUF) msgBuf        CHARACTER*(MAX_LEN_MBUF) msgBuf
89  C  
90  C     u/vIceRes :: residual of sea-ice momentum equations  C     u/vIceRes :: residual of sea-ice momentum equations
91        _RL uIceRes(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)        _RL uIceRes(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
92        _RL vIceRes(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)        _RL vIceRes(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
93    C     extra time level required for backward difference time stepping
94          _RL duIcNm1(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
95          _RL dvIcNm1(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
96  C     du/vIce   :: ice velocity increment to be added to u/vIce  C     du/vIce   :: ice velocity increment to be added to u/vIce
97        _RL duIce  (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)        _RL duIce  (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
98        _RL dvIce  (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)        _RL dvIce  (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
99  C     precomputed (= constant per Newton iteration) versions of  C     precomputed (= constant per Newton iteration) versions of
100  C     zeta, eta, and DWATN, press  C     zeta, eta, and DWATN, press
101        _RL zetaPre (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)        _RL zetaPre (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
102          _RL zetaZPre(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
103        _RL etaPre  (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)        _RL etaPre  (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
104          _RL etaZPre (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
105        _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)  
106  CEOP  CEOP
107    
108  C     Initialise  C     Initialise
# Line 102  C     Initialise Line 117  C     Initialise
117        recip_deltaT        = 1. _d 0 / SEAICE_deltaTdyn        recip_deltaT        = 1. _d 0 / SEAICE_deltaTdyn
118    
119        iOutFGMRES=0        iOutFGMRES=0
120  C     iOutFgmres=1 gives a little bit of output  C     with iOutFgmres=1, seaice_fgmres prints the residual at each iteration
121        IF ( debugLevel.GE.debLevA .AND.        IF ( debugLevel.GE.debLevC .AND.
122       &     DIFFERENT_MULTIPLE( SEAICE_monFreq, myTime, deltaTClock ) )       &     DIFFERENT_MULTIPLE( SEAICE_monFreq, myTime, deltaTClock ) )
123       &     iOutFGMRES=1       &     iOutFGMRES=1
124    
125  C      C     backward difference extrapolation factors
126          bdfFac = 0. _d 0
127          IF ( SEAICEuseBDF2 ) THEN
128           IF ( myIter.EQ.nIter0 .AND. SEAICEmomStartBDF.EQ.0 ) THEN
129            bdfFac = 0. _d 0
130           ELSE
131            bdfFac = 0.5 _d 0
132           ENDIF
133          ENDIF
134          bdfAlpha = 1. _d 0 + bdfFac
135    
136        DO bj=myByLo(myThid),myByHi(myThid)        DO bj=myByLo(myThid),myByHi(myThid)
137         DO bi=myBxLo(myThid),myBxHi(myThid)         DO bi=myBxLo(myThid),myBxHi(myThid)
138          DO J=1-Oly,sNy+Oly          DO J=1-OLy,sNy+OLy
139           DO I=1-Olx,sNx+Olx           DO I=1-OLx,sNx+OLx
140            uIceRes(I,J,bi,bj) = 0. _d 0            uIceRes(I,J,bi,bj) = 0. _d 0
141            vIceRes(I,J,bi,bj) = 0. _d 0            vIceRes(I,J,bi,bj) = 0. _d 0
142            duIce  (I,J,bi,bj) = 0. _d 0            duIce  (I,J,bi,bj) = 0. _d 0
143            dvIce  (I,J,bi,bj) = 0. _d 0            dvIce  (I,J,bi,bj) = 0. _d 0
144             ENDDO
145            ENDDO
146    C     cycle ice velocities
147            DO J=1-OLy,sNy+OLy
148             DO I=1-OLx,sNx+OLx
149              duIcNm1(I,J,bi,bj) = uIce(I,J,bi,bj) * bdfAlpha
150         &         + ( uIce(I,J,bi,bj) - uIceNm1(I,J,bi,bj) ) * bdfFac
151              dvIcNm1(I,J,bi,bj) = vIce(I,J,bi,bj) * bdfAlpha
152         &         + ( vIce(I,J,bi,bj) - vIceNm1(I,J,bi,bj) ) * bdfFac
153            uIceNm1(I,J,bi,bj) = uIce(I,J,bi,bj)            uIceNm1(I,J,bi,bj) = uIce(I,J,bi,bj)
154            vIceNm1(I,J,bi,bj) = vIce(I,J,bi,bj)            vIceNm1(I,J,bi,bj) = vIce(I,J,bi,bj)
155           ENDDO           ENDDO
156          ENDDO          ENDDO
157    C     As long as IMEX is not properly implemented leave this commented out
158    CML        IF ( .NOT.SEAICEuseIMEX ) THEN
159  C     Compute things that do no change during the Newton iteration:  C     Compute things that do no change during the Newton iteration:
160  C     sea-surface tilt and wind stress:  C     sea-surface tilt and wind stress:
161  C     FORCEX/Y0 - mass*(u/vIceNm1)/deltaT  C     FORCEX/Y0 - mass*(1.5*u/vIceNm1+0.5*(u/vIceNm1-u/vIceNm2))/deltaT
162          DO J=1-Oly,sNy+Oly          DO J=1-OLy,sNy+OLy
163           DO I=1-Olx,sNx+Olx           DO I=1-OLx,sNx+OLx
164            FORCEX(I,J,bi,bj) = FORCEX0(I,J,bi,bj)            FORCEX(I,J,bi,bj) = FORCEX0(I,J,bi,bj)
165       &         + seaiceMassU(I,J,bi,bj)*uIceNm1(I,J,bi,bj)*recip_deltaT           &         + seaiceMassU(I,J,bi,bj)*duIcNm1(I,J,bi,bj)*recip_deltaT
166            FORCEY(I,J,bi,bj) = FORCEY0(I,J,bi,bj)            FORCEY(I,J,bi,bj) = FORCEY0(I,J,bi,bj)
167       &         + seaiceMassV(I,J,bi,bj)*vIceNm1(I,J,bi,bj)*recip_deltaT           &         + seaiceMassV(I,J,bi,bj)*dvIcNm1(I,J,bi,bj)*recip_deltaT
168           ENDDO           ENDDO
169          ENDDO          ENDDO
170    CML        ENDIF
171         ENDDO         ENDDO
172        ENDDO        ENDDO
173  C     Start nonlinear Newton iteration: outer loop iteration  C     Start nonlinear Newton iteration: outer loop iteration
# Line 139  C     Start nonlinear Newton iteration: Line 176  C     Start nonlinear Newton iteration:
176         newtonIter = newtonIter + 1         newtonIter = newtonIter + 1
177  C     Compute initial residual F(u), (includes computation of global  C     Compute initial residual F(u), (includes computation of global
178  C     variables DWATN, zeta, and eta)  C     variables DWATN, zeta, and eta)
179         CALL SEAICE_CALC_RESIDUAL(         IF ( newtonIter .EQ. 1 ) CALL SEAICE_JFNK_UPDATE(
180       I      uIce, vIce,       I      duIce, dvIce,
181       O      uIceRes, vIceRes,       U      uIce, vIce, JFNKresidual,
182       I      newtonIter, 0, myTime, myIter, myThid )       O      uIceRes, vIceRes,
183         CALL EXCH_UV_XY_RL( uIceRes, vIceRes,.TRUE.,myThid)       I      newtonIter, myTime, myIter, myThid )
184  C     local copies of precomputed coefficients that are to stay  C     local copies of precomputed coefficients that are to stay
185  C     constant for the preconditioner  C     constant for the preconditioner
186         DO bj=myByLo(myThid),myByHi(myThid)         DO bj=myByLo(myThid),myByHi(myThid)
187          DO bi=myBxLo(myThid),myBxHi(myThid)          DO bi=myBxLo(myThid),myBxHi(myThid)
188           DO j=1-Oly,sNy+Oly           DO j=1-OLy,sNy+OLy
189            DO i=1-Olx,sNx+Olx            DO i=1-OLx,sNx+OLx
190              zetaPre(I,J,bi,bj) =  zeta(I,J,bi,bj)             zetaPre(I,J,bi,bj) =  zeta(I,J,bi,bj)
191               etaPre(I,J,bi,bj) =   eta(I,J,bi,bj)             zetaZPre(I,J,bi,bj)= zetaZ(I,J,bi,bj)
192              dwatPre(I,J,bi,bj) = DWATN(I,J,bi,bj)              etaPre(I,J,bi,bj) =   eta(I,J,bi,bj)
193             pressPre(I,J,bi,bj) = press(I,J,bi,bj)             etaZPre(I,J,bi,bj) =  etaZ(I,J,bi,bj)
194               dwatPre(I,J,bi,bj) = DWATN(I,J,bi,bj)
195            ENDDO            ENDDO
196           ENDDO           ENDDO
197          ENDDO          ENDDO
198         ENDDO         ENDDO
 C      
        DO bj=myByLo(myThid),myByHi(myThid)  
         DO bi=myBxLo(myThid),myBxHi(myThid)  
          JFNKresidualTile(bi,bj) = 0. _d 0  
          DO J=1,sNy  
           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  
        JFNKresidual = SQRT(JFNKresidual)  
199  C     compute convergence criterion for linear preconditioned FGMRES  C     compute convergence criterion for linear preconditioned FGMRES
200         JFNKgamma_lin = JFNKgamma_lin_max         JFNKgamma_lin = JFNKgamma_lin_max
201         IF ( newtonIter.GT.1.AND.newtonIter.LE.100         IF ( newtonIter.GT.1.AND.newtonIter.LE.SEAICE_JFNK_tolIter
202       &      .AND.JFNKresidual.LT.JFNKres_t ) THEN       &      .AND.JFNKresidual.LT.JFNKres_t ) THEN
203  C     Eisenstat, 1996, equ.(2.6)        C     Eisenstat and Walker (1996), eq.(2.6)
204          phi_e = 1. _d 0          JFNKgamma_lin = SEAICE_JFNKphi
205          alp_e = 1. _d 0       &       *( JFNKresidual/JFNKresidualKm1 )**SEAICE_JFNKalpha
         JFNKgamma_lin = phi_e*( JFNKresidual/JFNKresidualKm1 )**alp_e  
206          JFNKgamma_lin = min(JFNKgamma_lin_max, JFNKgamma_lin)          JFNKgamma_lin = min(JFNKgamma_lin_max, JFNKgamma_lin)
207          JFNKgamma_lin = max(JFNKgamma_lin_min, JFNKgamma_lin)          JFNKgamma_lin = max(JFNKgamma_lin_min, JFNKgamma_lin)
208         ENDIF         ENDIF
209  C     save the residual for the next iteration  C     save the residual for the next iteration
210         JFNKresidualKm1 = JFNKresidual         JFNKresidualKm1 = JFNKresidual
211  C  
212  C     The Krylov iteration using FGMRES, the preconditioner is LSOR  C     The Krylov iteration using FGMRES, the preconditioner is LSOR
213  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
214  C     down.  C     down.
# Line 204  C     krylovIter is mapped into "its" in Line 216  C     krylovIter is mapped into "its" in
216  C     in that routine  C     in that routine
217         krylovIter    = 0         krylovIter    = 0
218         iCode         = 0         iCode         = 0
219         IF ( debugLevel.GE.debLevA ) THEN    
         _BEGIN_MASTER( myThid )  
         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 )  
         _END_MASTER( myThid )  
        ENDIF  
 C  
220         JFNKconverged = JFNKresidual.LT.JFNKtol         JFNKconverged = JFNKresidual.LT.JFNKtol
221  C  
222  C     do Krylov loop only if convergence is not reached  C     do Krylov loop only if convergence is not reached
223  C  
224         IF ( .NOT.JFNKconverged ) THEN         IF ( .NOT.JFNKconverged ) THEN
225  C  
226  C     start Krylov iteration (FGMRES)  C     start Krylov iteration (FGMRES)
227  C  
228          krylovConverged = .FALSE.          krylovConverged = .FALSE.
229          FGMRESeps = JFNKgamma_lin * JFNKresidual          FGMRESeps = JFNKgamma_lin * JFNKresidual
230          DO WHILE ( .NOT.krylovConverged )          DO WHILE ( .NOT.krylovConverged )
231  C     solution vector sol = du/vIce  C     solution vector sol = du/vIce
232  C     residual vector (rhs) Fu = u/vIceRes  C     residual vector (rhs) Fu = u/vIceRes
233  C     output work vectors wk1, -> input work vector wk2  C     output work vectors wk1, -> input work vector wk2
234  C      
235           CALL SEAICE_FGMRES_DRIVER(           CALL SEAICE_FGMRES_DRIVER(
236       I        uIceRes, vIceRes,       I        uIceRes, vIceRes,
237       U        duIce, dvIce, iCode,       U        duIce, dvIce, iCode,
238       I        FGMRESeps, iOutFGMRES,       I        FGMRESeps, iOutFGMRES,
239       I        newtonIter, krylovIter, myTime, myIter, myThid )       I        newtonIter, krylovIter, myTime, myIter, myThid )
# Line 241  C     or product of matrix (Jacobian) ti Line 242  C     or product of matrix (Jacobian) ti
242  C     iteration  C     iteration
243           IF (iCode.EQ.1) THEN           IF (iCode.EQ.1) THEN
244  C     Call preconditioner  C     Call preconditioner
245            CALL SEAICE_PRECONDITIONER(            IF ( SOLV_MAX_ITERS .GT. 0 )
246       U         duIce, dvIce,       &         CALL SEAICE_PRECONDITIONER(
247       I         zetaPre, etaPre, dwatPre, pressPre,       U         duIce, dvIce,
248         I         zetaPre, etaPre, etaZpre, zetaZpre, dwatPre,
249       I         newtonIter, krylovIter, myTime, myIter, myThid )       I         newtonIter, krylovIter, myTime, myIter, myThid )
250           ELSEIF (iCode.GE.2) THEN           ELSEIF (iCode.GE.2) THEN
251  C     Compute Jacobian times vector  C     Compute Jacobian times vector
252            CALL SEAICE_JACVEC(            CALL SEAICE_JACVEC(
253       I         uIce, vIce, uIceRes, vIceRes,       I         uIce, vIce, uIceRes, vIceRes,
254       U         duIce, dvIce,         U         duIce, dvIce,
255       I         newtonIter, krylovIter, myTime, myIter, myThid )       I         newtonIter, krylovIter, myTime, myIter, myThid )
256           ENDIF           ENDIF
257           krylovConverged = iCode.EQ.0           krylovConverged = iCode.EQ.0
# Line 259  C     End of Krylov iterate Line 261  C     End of Krylov iterate
261  C     some output diagnostics  C     some output diagnostics
262          IF ( debugLevel.GE.debLevA ) THEN          IF ( debugLevel.GE.debLevA ) THEN
263           _BEGIN_MASTER( myThid )           _BEGIN_MASTER( myThid )
264             totalNewtonItersLoc =
265         &        SEAICEnewtonIterMax*(myIter-nIter0)+newtonIter
266             WRITE(msgBuf,'(2A,2(1XI6),2E12.5)')
267         &        ' S/R SEAICE_JFNK: Newton iterate / total, ',
268         &        'JFNKgamma_lin, initial norm = ',
269         &        newtonIter, totalNewtonItersLoc,
270         &        JFNKgamma_lin,JFNKresidual
271             CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
272         &        SQUEEZE_RIGHT, myThid )
273           WRITE(msgBuf,'(3(A,I6))')           WRITE(msgBuf,'(3(A,I6))')
274       &        ' S/R SEAICE_JFNK: Newton iterate / total = ', newtonIter,       &        ' S/R SEAICE_JFNK: Newton iterate / total = ',newtonIter,
275       &        ' / ', SEAICEnewtonIterMax*(myIter-nIter0)+newtonIter,       &        ' / ', totalNewtonItersLoc,
276       &        ', Nb. of FGMRES iterations = ', krylovIter       &        ', Nb. of FGMRES iterations = ', krylovIter
277           CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,           CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
278       &        SQUEEZE_RIGHT, myThid )       &        SQUEEZE_RIGHT, myThid )
# Line 270  C     some output diagnostics Line 281  C     some output diagnostics
281          IF ( krylovIter.EQ.SEAICEkrylovIterMax ) THEN          IF ( krylovIter.EQ.SEAICEkrylovIterMax ) THEN
282           krylovFails = krylovFails + 1           krylovFails = krylovFails + 1
283          ENDIF          ENDIF
284    C     Set the stopping criterion for the Newton iteration and the
285    C     criterion for the transition from accurate to approximate FGMRES
286            IF ( newtonIter .EQ. 1 ) THEN
287             JFNKtol=JFNKgamma_nonlin*JFNKresidual
288             IF ( JFNKres_tFac .NE. UNSET_RL )
289         &        JFNKres_t = JFNKresidual * JFNKres_tFac
290            ENDIF
291  C     Update linear solution vector and return to Newton iteration  C     Update linear solution vector and return to Newton iteration
292    C     Do a linesearch if necessary, and compute a new residual.
293    C     Note that it should be possible to do the following operations
294    C     at the beginning of the Newton iteration, thereby saving us from
295    C     the extra call of seaice_jfnk_update, but unfortunately that
296    C     changes the results, so we leave the stuff here for now.
297            CALL SEAICE_JFNK_UPDATE(
298         I       duIce, dvIce,
299         U       uIce, vIce, JFNKresidual,
300         O       uIceRes, vIceRes,
301         I       newtonIter, myTime, myIter, myThid )
302    C     reset du/vIce here instead of setting sol = 0 in seaice_fgmres_driver
303          DO bj=myByLo(myThid),myByHi(myThid)          DO bj=myByLo(myThid),myByHi(myThid)
304           DO bi=myBxLo(myThid),myBxHi(myThid)           DO bi=myBxLo(myThid),myBxHi(myThid)
305            DO J=1-Oly,sNy+Oly            DO J=1-OLy,sNy+OLy
306             DO I=1-Olx,sNx+Olx             DO I=1-OLx,sNx+OLx
             uIce(I,J,bi,bj) = uIce(I,J,bi,bj)+duIce(I,J,bi,bj)  
             vIce(I,J,bi,bj) = vIce(I,J,bi,bj)+dvIce(I,J,bi,bj)  
 C     reset du/vIce here instead of setting sol = 0 in seaice_fgmres_driver  
307              duIce(I,J,bi,bj)= 0. _d 0              duIce(I,J,bi,bj)= 0. _d 0
308              dvIce(I,J,bi,bj)= 0. _d 0              dvIce(I,J,bi,bj)= 0. _d 0
309             ENDDO             ENDDO
310            ENDDO            ENDDO
311           ENDDO           ENDDO
312          ENDDO          ENDDO
 C     Set the stopping criterion for the Newton iteration  
         IF ( newtonIter .EQ. 1 ) JFNKtol=JFNKgamma_nonlin*JFNKresidual  
313         ENDIF         ENDIF
314  C     end of Newton iterate  C     end of Newton iterate
315        ENDDO        ENDDO
316  C  
317  C--   Output diagnostics  C--   Output diagnostics
318  C  
319        IF ( SEAICE_monFreq .GT. 0. _d 0 ) THEN        IF ( SEAICE_monFreq .GT. 0. _d 0 ) THEN
320  C     Count iterations  C     Count iterations
321         totalJFNKtimeSteps = totalJFNKtimeSteps + 1         totalJFNKtimeSteps = totalJFNKtimeSteps + 1
# Line 300  C     Count iterations Line 324  C     Count iterations
324  C     Record failure  C     Record failure
325         totalKrylovFails   = totalKrylovFails + krylovFails         totalKrylovFails   = totalKrylovFails + krylovFails
326         IF ( newtonIter .EQ. SEAICEnewtonIterMax ) THEN         IF ( newtonIter .EQ. SEAICEnewtonIterMax ) THEN
327          totalNewtonFails = totalNewtonFails + 1          totalNewtonFails = totalNewtonFails + 1
328         ENDIF         ENDIF
329        ENDIF        ENDIF
330  C     Decide whether it is time to dump and reset the counter  C     Decide whether it is time to dump and reset the counter
331        IF ( DIFFERENT_MULTIPLE(SEAICE_monFreq,myTime+deltaTClock,        writeNow = DIFFERENT_MULTIPLE(SEAICE_monFreq,
332       &     deltaTClock) ) THEN       &     myTime+deltaTClock, deltaTClock)
333    #ifdef ALLOW_CAL
334          IF ( useCAL ) THEN
335           CALL CAL_TIME2DUMP(
336         I      zeroRL, SEAICE_monFreq,  deltaTClock,
337         U      writeNow,
338         I      myTime+deltaTclock, myIter+1, myThid )
339          ENDIF
340    #endif
341          IF ( writeNow ) THEN
342         _BEGIN_MASTER( myThid )         _BEGIN_MASTER( myThid )
343         WRITE(msgBuf,'(A)')         WRITE(msgBuf,'(A)')
344       &' // ======================================================='       &' // ======================================================='
345         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
346       &      SQUEEZE_RIGHT, myThid )       &      SQUEEZE_RIGHT, myThid )
347         WRITE(msgBuf,'(A)') ' // Begin JFNK statistics'         WRITE(msgBuf,'(A)') ' // Begin JFNK statistics'
348         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
349       &      SQUEEZE_RIGHT, myThid )       &      SQUEEZE_RIGHT, myThid )
350         WRITE(msgBuf,'(A)')         WRITE(msgBuf,'(A)')
351       &' // ======================================================='       &' // ======================================================='
352         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
353       &      SQUEEZE_RIGHT, myThid )       &      SQUEEZE_RIGHT, myThid )
354         WRITE(msgBuf,'(A,I10)')         WRITE(msgBuf,'(A,I10)')
355       &      ' %JFNK_MON: time step              = ', myIter+1       &      ' %JFNK_MON: time step              = ', myIter+1
356         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
357       &      SQUEEZE_RIGHT, myThid )       &      SQUEEZE_RIGHT, myThid )
358         WRITE(msgBuf,'(A,I10)')         WRITE(msgBuf,'(A,I10)')
359       &      ' %JFNK_MON: Nb. of time steps      = ', totalJFNKtimeSteps       &      ' %JFNK_MON: Nb. of time steps      = ', totalJFNKtimeSteps
360         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
361       &      SQUEEZE_RIGHT, myThid )       &      SQUEEZE_RIGHT, myThid )
362         WRITE(msgBuf,'(A,I10)')         WRITE(msgBuf,'(A,I10)')
363       &      ' %JFNK_MON: Nb. of Newton steps    = ', totalNewtonIters       &      ' %JFNK_MON: Nb. of Newton steps    = ', totalNewtonIters
364         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
365       &      SQUEEZE_RIGHT, myThid )       &      SQUEEZE_RIGHT, myThid )
366         WRITE(msgBuf,'(A,I10)')         WRITE(msgBuf,'(A,I10)')
367       &      ' %JFNK_MON: Nb. of Krylov steps    = ', totalKrylovIters       &      ' %JFNK_MON: Nb. of Krylov steps    = ', totalKrylovIters
368         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
369       &      SQUEEZE_RIGHT, myThid )       &      SQUEEZE_RIGHT, myThid )
370         WRITE(msgBuf,'(A,I10)')         WRITE(msgBuf,'(A,I10)')
371       &      ' %JFNK_MON: Nb. of Newton failures = ', totalNewtonFails       &      ' %JFNK_MON: Nb. of Newton failures = ', totalNewtonFails
372         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
373       &      SQUEEZE_RIGHT, myThid )       &      SQUEEZE_RIGHT, myThid )
374         WRITE(msgBuf,'(A,I10)')         WRITE(msgBuf,'(A,I10)')
375       &      ' %JFNK_MON: Nb. of Krylov failures = ', totalKrylovFails       &      ' %JFNK_MON: Nb. of Krylov failures = ', totalKrylovFails
376         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
377       &      SQUEEZE_RIGHT, myThid )       &      SQUEEZE_RIGHT, myThid )
378         WRITE(msgBuf,'(A)')         WRITE(msgBuf,'(A)')
379       &' // ======================================================='       &' // ======================================================='
380         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
381       &      SQUEEZE_RIGHT, myThid )       &      SQUEEZE_RIGHT, myThid )
382         WRITE(msgBuf,'(A)') ' // Begin JFNK statistics'         WRITE(msgBuf,'(A)') ' // End JFNK statistics'
383         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
384       &      SQUEEZE_RIGHT, myThid )       &      SQUEEZE_RIGHT, myThid )
385         WRITE(msgBuf,'(A)')         WRITE(msgBuf,'(A)')
386       &' // ======================================================='       &' // ======================================================='
387         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
388       &      SQUEEZE_RIGHT, myThid )       &      SQUEEZE_RIGHT, myThid )
# Line 366  C     Print more debugging information Line 399  C     Print more debugging information
399        IF ( debugLevel.GE.debLevA ) THEN        IF ( debugLevel.GE.debLevA ) THEN
400         IF ( newtonIter .EQ. SEAICEnewtonIterMax ) THEN         IF ( newtonIter .EQ. SEAICEnewtonIterMax ) THEN
401          _BEGIN_MASTER( myThid )          _BEGIN_MASTER( myThid )
402          WRITE(msgBuf,'(A,I10)')          WRITE(msgBuf,'(A,I10)')
403       &       ' S/R SEAICE_JFNK: JFNK did not converge in timestep ',       &       ' S/R SEAICE_JFNK: JFNK did not converge in timestep ',
404       &       myIter+1       &       myIter+1
405          CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,          CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
# Line 375  C     Print more debugging information Line 408  C     Print more debugging information
408         ENDIF         ENDIF
409         IF ( krylovFails .GT. 0 ) THEN         IF ( krylovFails .GT. 0 ) THEN
410          _BEGIN_MASTER( myThid )          _BEGIN_MASTER( myThid )
411          WRITE(msgBuf,'(A,I4,A,I10)')          WRITE(msgBuf,'(A,I4,A,I10)')
412       &       ' S/R SEAICE_JFNK: FGMRES did not converge ',       &       ' S/R SEAICE_JFNK: FGMRES did not converge ',
413       &       krylovFails, ' times in timestep ', myIter+1       &       krylovFails, ' times in timestep ', myIter+1
414          CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,          CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
# Line 383  C     Print more debugging information Line 416  C     Print more debugging information
416          _END_MASTER( myThid )          _END_MASTER( myThid )
417         ENDIF         ENDIF
418         _BEGIN_MASTER( myThid )         _BEGIN_MASTER( myThid )
419         WRITE(msgBuf,'(A,I6,A,I10)')         WRITE(msgBuf,'(A,I6,A,I10)')
420       &      ' S/R SEAICE_JFNK: Total number FGMRES iterations = ',       &      ' S/R SEAICE_JFNK: Total number FGMRES iterations = ',
421       &      totalKrylovItersLoc, ' in timestep ', myIter+1       &      totalKrylovItersLoc, ' in timestep ', myIter+1
422         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,         CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
# Line 391  C     Print more debugging information Line 424  C     Print more debugging information
424         _END_MASTER( myThid )         _END_MASTER( myThid )
425        ENDIF        ENDIF
426    
427  #endif /* SEAICE_ALLOW_DYNAMICS and SEAICE_CGRID and SEAICE_ALLOW_JFNK */        RETURN
428          END
429    
430    C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
431    CBOP
432    C     !ROUTINE: SEAICE_JFNK_UPDATE
433    C     !INTERFACE:
434    
435          SUBROUTINE SEAICE_JFNK_UPDATE(
436         I     duIce, dvIce,
437         U     uIce, vIce, JFNKresidual,
438         O     uIceRes, vIceRes,
439         I     newtonIter, myTime, myIter, myThid )
440    
441    C     !DESCRIPTION: \bv
442    C     *==========================================================*
443    C     | SUBROUTINE SEAICE_JFNK_UPDATE
444    C     | o Update velocities with incremental solutions of FGMRES
445    C     | o compute residual of updated solutions and do
446    C     | o linesearch:
447    C     |   reduce update until residual is smaller than previous
448    C     |   one (input)
449    C     *==========================================================*
450    C     | written by Martin Losch, Jan 2013
451    C     *==========================================================*
452    C     \ev
453    
454    C     !USES:
455          IMPLICIT NONE
456    
457    C     === Global variables ===
458    #include "SIZE.h"
459    #include "EEPARAMS.h"
460    #include "PARAMS.h"
461    #include "SEAICE_SIZE.h"
462    #include "SEAICE_PARAMS.h"
463    
464    C     !INPUT/OUTPUT PARAMETERS:
465    C     === Routine arguments ===
466    C     myTime :: Simulation time
467    C     myIter :: Simulation timestep number
468    C     myThid :: my Thread Id. number
469    C     newtonIter :: current iterate of Newton iteration
470          _RL     myTime
471          INTEGER myIter
472          INTEGER myThid
473          INTEGER newtonIter
474    C     JFNKresidual :: Residual at the beginning of the FGMRES iteration,
475    C                     changes with newtonIter (updated)
476          _RL     JFNKresidual
477    C     du/vIce   :: ice velocity increment to be added to u/vIce (input)
478          _RL duIce  (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
479          _RL dvIce  (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
480    C     u/vIce    :: ice velocity increment to be added to u/vIce (updated)
481          _RL uIce   (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
482          _RL vIce   (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
483    C     u/vIceRes :: residual of sea-ice momentum equations (output)
484          _RL uIceRes(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
485          _RL vIceRes(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
486    
487    C     !LOCAL VARIABLES:
488    C     === Local variables ===
489    C     i,j,bi,bj :: loop indices
490          INTEGER i,j,bi,bj
491          INTEGER l
492          _RL     resLoc, facLS
493          LOGICAL doLineSearch
494    C     nVec    :: size of the input vector(s)
495    C     resTmp  :: vector version of the residuals
496          INTEGER nVec
497          PARAMETER ( nVec  = 2*sNx*sNy )
498          _RL resTmp (nVec,1,nSx,nSy)
499    
500          CHARACTER*(MAX_LEN_MBUF) msgBuf
501    CEOP
502    
503    C     Initialise some local variables
504          l = 0
505          resLoc = JFNKresidual
506          facLS = 1. _d 0
507          doLineSearch = .TRUE.
508          DO WHILE ( doLineSearch )
509    C     Create update
510           DO bj=myByLo(myThid),myByHi(myThid)
511            DO bi=myBxLo(myThid),myBxHi(myThid)
512             DO J=1-OLy,sNy+OLy
513              DO I=1-OLx,sNx+OLx
514               uIce(I,J,bi,bj) = uIce(I,J,bi,bj)+facLS*duIce(I,J,bi,bj)
515               vIce(I,J,bi,bj) = vIce(I,J,bi,bj)+facLS*dvIce(I,J,bi,bj)
516              ENDDO
517             ENDDO
518            ENDDO
519           ENDDO
520    C     Compute current residual F(u), (includes re-computation of global
521    C     variables DWATN, zeta, and eta, i.e. they are different after this)
522           CALL SEAICE_CALC_RESIDUAL(
523         I      uIce, vIce,
524         O      uIceRes, vIceRes,
525         I      newtonIter, 0, myTime, myIter, myThid )
526    C     Important: Compute the norm of the residual using the same scalar
527    C     product that SEAICE_FGMRES does
528           CALL SEAICE_MAP2VEC(nVec,uIceRes,vIceRes,resTmp,.TRUE.,myThid)
529           CALL SEAICE_SCALPROD(nVec,1,1,1,resTmp,resTmp,resLoc,myThid)
530           resLoc = SQRT(resLoc)
531    C     Determine, if we need more iterations
532           doLineSearch = resLoc .GE. JFNKresidual
533    C     Limit the maximum number of iterations arbitrarily to four
534           doLineSearch = doLineSearch .AND. l .LT. 4
535    C     For the first iteration du/vIce = 0 and there will be no
536    C     improvement of the residual possible, so we do only the first
537    C     iteration
538           IF ( newtonIter .EQ. 1 ) doLineSearch = .FALSE.
539    C     Only start a linesearch after some Newton iterations
540           IF ( newtonIter .LE. SEAICE_JFNK_lsIter ) doLineSearch = .FALSE.
541    C     Increment counter
542           l = l + 1
543    C     some output diagnostics
544           IF ( debugLevel.GE.debLevA .AND. doLineSearch ) THEN
545            _BEGIN_MASTER( myThid )
546            WRITE(msgBuf,'(2A,2(1XI6),3E12.5)')
547         &       ' S/R SEAICE_JFNK_UPDATE: Newton iter, LSiter, ',
548         &       'facLS, JFNKresidual, resLoc = ',
549         &        newtonIter, l, facLS, JFNKresidual, resLoc
550            CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
551         &       SQUEEZE_RIGHT, myThid )
552            _END_MASTER( myThid )
553           ENDIF
554    C     Get ready for the next iteration: after adding du/vIce in the first
555    C     iteration, we substract 0.5*du/vIce from u/vIce in the next
556    C     iterations, 0.25*du/vIce in the second, etc.
557           facLS = - 0.5 _d 0 * ABS(facLS)
558          ENDDO
559    C     This is the new residual
560          JFNKresidual = resLoc
561    
562    #endif /* SEAICE_ALLOW_JFNK */
563    
564        RETURN        RETURN
565        END        END

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

  ViewVC Help
Powered by ViewVC 1.1.22