/[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.21 by mlosch, Thu Apr 4 07:02:51 2013 UTC revision 1.29 by mlosch, Wed Jan 27 14:03:34 2016 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:  C--  File seaice_jfnk.F: seaice jfnk dynamical solver S/R:
10  C--   Contents  C--   Contents
# Line 60  C     !FUNCTIONS: Line 63  C     !FUNCTIONS:
63    
64  C     !LOCAL VARIABLES:  C     !LOCAL VARIABLES:
65  C     === Local variables ===  C     === Local variables ===
66  C     i,j,bi,bj :: loop indices  C     i,j,k,bi,bj :: loop indices
67        INTEGER i,j,bi,bj        INTEGER i,j,k,bi,bj
68  C     loop indices  C     loop indices
69        INTEGER newtonIter        INTEGER newtonIter
70        INTEGER krylovIter, krylovFails        INTEGER krylovIter, krylovFails
71        INTEGER totalKrylovItersLoc, totalNewtonItersLoc        INTEGER totalKrylovItersLoc, totalNewtonItersLoc
72    C     FGMRES parameters
73    C     im      :: size of Krylov space
74    C     ifgmres :: interation counter
75          INTEGER im
76          PARAMETER ( im = 50 )
77          INTEGER ifgmres
78  C     FGMRES flag that determines amount of output messages of fgmres  C     FGMRES flag that determines amount of output messages of fgmres
79        INTEGER iOutFGMRES        INTEGER iOutFGMRES
80  C     FGMRES flag that indicates what fgmres wants us to do next  C     FGMRES flag that indicates what fgmres wants us to do next
# Line 73  C     FGMRES flag that indicates what fg Line 82  C     FGMRES flag that indicates what fg
82        _RL     JFNKresidual        _RL     JFNKresidual
83        _RL     JFNKresidualKm1        _RL     JFNKresidualKm1
84  C     parameters to compute convergence criterion  C     parameters to compute convergence criterion
85        _RL     phi_e, alp_e, JFNKgamma_lin        _RL     JFNKgamma_lin
86        _RL     FGMRESeps        _RL     FGMRESeps
87        _RL     JFNKtol        _RL     JFNKtol
88    C     backward differences extrapolation factors
89          _RL bdfFac, bdfAlpha
90    C
91        _RL     recip_deltaT        _RL     recip_deltaT
92        LOGICAL JFNKconverged, krylovConverged        LOGICAL JFNKconverged, krylovConverged
93        LOGICAL writeNow        LOGICAL writeNow
# Line 85  C     parameters to compute convergence Line 96  C     parameters to compute convergence
96  C     u/vIceRes :: residual of sea-ice momentum equations  C     u/vIceRes :: residual of sea-ice momentum equations
97        _RL uIceRes(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)        _RL uIceRes(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
98        _RL vIceRes(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)        _RL vIceRes(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
99    C     extra time level required for backward difference time stepping
100          _RL duIcNm1(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
101          _RL dvIcNm1(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
102  C     du/vIce   :: ice velocity increment to be added to u/vIce  C     du/vIce   :: ice velocity increment to be added to u/vIce
103        _RL duIce  (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)        _RL duIce  (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
104        _RL dvIce  (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)        _RL dvIce  (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
105  C     precomputed (= constant per Newton iteration) versions of  C     precomputed (= constant per Newton iteration) versions of
106  C     zeta, eta, and DWATN, press  C     zeta, eta, and DWATN, press
107        _RL zetaPre (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)        _RL zetaPre (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
108          _RL zetaZPre(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
109        _RL etaPre  (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)        _RL etaPre  (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
110        _RL etaZPre (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)        _RL etaZPre (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
111        _RL dwatPre (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)        _RL dwatPre (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
112    C     work arrays
113          _RL rhs(nVec,nSx,nSy), sol(nVec,nSx,nSy)
114          _RL vv(nVec,im+1,nSx,nSy), w(nVec,im,nSx,nSy)
115          _RL wk1(nVec,nSx,nSy), wk2(nVec,nSx,nSy)
116  CEOP  CEOP
117    
118  C     Initialise  C     Initialise
# Line 113  C     with iOutFgmres=1, seaice_fgmres p Line 132  C     with iOutFgmres=1, seaice_fgmres p
132       &     DIFFERENT_MULTIPLE( SEAICE_monFreq, myTime, deltaTClock ) )       &     DIFFERENT_MULTIPLE( SEAICE_monFreq, myTime, deltaTClock ) )
133       &     iOutFGMRES=1       &     iOutFGMRES=1
134    
135    C     backward difference extrapolation factors
136          bdfFac = 0. _d 0
137          IF ( SEAICEuseBDF2 ) THEN
138           IF ( myIter.EQ.nIter0 .AND. SEAICEmomStartBDF.EQ.0 ) THEN
139            bdfFac = 0. _d 0
140           ELSE
141            bdfFac = 0.5 _d 0
142           ENDIF
143          ENDIF
144          bdfAlpha = 1. _d 0 + bdfFac
145    
146        DO bj=myByLo(myThid),myByHi(myThid)        DO bj=myByLo(myThid),myByHi(myThid)
147         DO bi=myBxLo(myThid),myBxHi(myThid)         DO bi=myBxLo(myThid),myBxHi(myThid)
148          DO J=1-OLy,sNy+OLy          DO J=1-OLy,sNy+OLy
# Line 121  C     with iOutFgmres=1, seaice_fgmres p Line 151  C     with iOutFgmres=1, seaice_fgmres p
151            vIceRes(I,J,bi,bj) = 0. _d 0            vIceRes(I,J,bi,bj) = 0. _d 0
152            duIce  (I,J,bi,bj) = 0. _d 0            duIce  (I,J,bi,bj) = 0. _d 0
153            dvIce  (I,J,bi,bj) = 0. _d 0            dvIce  (I,J,bi,bj) = 0. _d 0
154             ENDDO
155            ENDDO
156    C     cycle ice velocities
157            DO J=1-OLy,sNy+OLy
158             DO I=1-OLx,sNx+OLx
159              duIcNm1(I,J,bi,bj) = uIce(I,J,bi,bj) * bdfAlpha
160         &         + ( uIce(I,J,bi,bj) - uIceNm1(I,J,bi,bj) ) * bdfFac
161              dvIcNm1(I,J,bi,bj) = vIce(I,J,bi,bj) * bdfAlpha
162         &         + ( vIce(I,J,bi,bj) - vIceNm1(I,J,bi,bj) ) * bdfFac
163            uIceNm1(I,J,bi,bj) = uIce(I,J,bi,bj)            uIceNm1(I,J,bi,bj) = uIce(I,J,bi,bj)
164            vIceNm1(I,J,bi,bj) = vIce(I,J,bi,bj)            vIceNm1(I,J,bi,bj) = vIce(I,J,bi,bj)
165           ENDDO           ENDDO
166          ENDDO          ENDDO
167    C     As long as IMEX is not properly implemented leave this commented out
168    CML        IF ( .NOT.SEAICEuseIMEX ) THEN
169  C     Compute things that do no change during the Newton iteration:  C     Compute things that do no change during the Newton iteration:
170  C     sea-surface tilt and wind stress:  C     sea-surface tilt and wind stress:
171  C     FORCEX/Y0 - mass*(u/vIceNm1)/deltaT  C     FORCEX/Y0 - mass*(1.5*u/vIceNm1+0.5*(u/vIceNm1-u/vIceNm2))/deltaT
172          DO J=1-OLy,sNy+OLy          DO J=1-OLy,sNy+OLy
173           DO I=1-OLx,sNx+OLx           DO I=1-OLx,sNx+OLx
174            FORCEX(I,J,bi,bj) = FORCEX0(I,J,bi,bj)            FORCEX(I,J,bi,bj) = FORCEX0(I,J,bi,bj)
175       &         + seaiceMassU(I,J,bi,bj)*uIceNm1(I,J,bi,bj)*recip_deltaT       &         + seaiceMassU(I,J,bi,bj)*duIcNm1(I,J,bi,bj)*recip_deltaT
176            FORCEY(I,J,bi,bj) = FORCEY0(I,J,bi,bj)            FORCEY(I,J,bi,bj) = FORCEY0(I,J,bi,bj)
177       &         + seaiceMassV(I,J,bi,bj)*vIceNm1(I,J,bi,bj)*recip_deltaT       &         + seaiceMassV(I,J,bi,bj)*dvIcNm1(I,J,bi,bj)*recip_deltaT
178           ENDDO           ENDDO
179          ENDDO          ENDDO
180    CML        ENDIF
181         ENDDO         ENDDO
182        ENDDO        ENDDO
183  C     Start nonlinear Newton iteration: outer loop iteration  C     Start nonlinear Newton iteration: outer loop iteration
# Line 156  C     constant for the preconditioner Line 198  C     constant for the preconditioner
198           DO j=1-OLy,sNy+OLy           DO j=1-OLy,sNy+OLy
199            DO i=1-OLx,sNx+OLx            DO i=1-OLx,sNx+OLx
200             zetaPre(I,J,bi,bj) =  zeta(I,J,bi,bj)             zetaPre(I,J,bi,bj) =  zeta(I,J,bi,bj)
201               zetaZPre(I,J,bi,bj)= zetaZ(I,J,bi,bj)
202              etaPre(I,J,bi,bj) =   eta(I,J,bi,bj)              etaPre(I,J,bi,bj) =   eta(I,J,bi,bj)
203             etaZPre(I,J,bi,bj) =  etaZ(I,J,bi,bj)             etaZPre(I,J,bi,bj) =  etaZ(I,J,bi,bj)
204             dwatPre(I,J,bi,bj) = DWATN(I,J,bi,bj)             dwatPre(I,J,bi,bj) = DWATN(I,J,bi,bj)
# Line 167  C     compute convergence criterion for Line 210  C     compute convergence criterion for
210         JFNKgamma_lin = JFNKgamma_lin_max         JFNKgamma_lin = JFNKgamma_lin_max
211         IF ( newtonIter.GT.1.AND.newtonIter.LE.SEAICE_JFNK_tolIter         IF ( newtonIter.GT.1.AND.newtonIter.LE.SEAICE_JFNK_tolIter
212       &      .AND.JFNKresidual.LT.JFNKres_t ) THEN       &      .AND.JFNKresidual.LT.JFNKres_t ) THEN
213  C     Eisenstat, 1996, equ.(2.6)  C     Eisenstat and Walker (1996), eq.(2.6)
214          phi_e = 1. _d 0          JFNKgamma_lin = SEAICE_JFNKphi
215          alp_e = 1. _d 0       &       *( JFNKresidual/JFNKresidualKm1 )**SEAICE_JFNKalpha
         JFNKgamma_lin = phi_e*( JFNKresidual/JFNKresidualKm1 )**alp_e  
216          JFNKgamma_lin = min(JFNKgamma_lin_max, JFNKgamma_lin)          JFNKgamma_lin = min(JFNKgamma_lin_max, JFNKgamma_lin)
217          JFNKgamma_lin = max(JFNKgamma_lin_min, JFNKgamma_lin)          JFNKgamma_lin = max(JFNKgamma_lin_min, JFNKgamma_lin)
218         ENDIF         ENDIF
# Line 195  C     start Krylov iteration (FGMRES) Line 237  C     start Krylov iteration (FGMRES)
237    
238          krylovConverged = .FALSE.          krylovConverged = .FALSE.
239          FGMRESeps = JFNKgamma_lin * JFNKresidual          FGMRESeps = JFNKgamma_lin * JFNKresidual
240    C     map first guess sol; it is zero because the solution is a correction
241           CALL SEAICE_MAP2VEC(nVec,duIce,dvIce,sol,.TRUE.,myThid)
242    C     map rhs and change its sign because we are solving J*u = -F
243            CALL SEAICE_MAP2VEC(nVec,-uIceRes,-vIceRes,rhs,.TRUE.,myThid)
244          DO WHILE ( .NOT.krylovConverged )          DO WHILE ( .NOT.krylovConverged )
245  C     solution vector sol = du/vIce  C     solution vector sol = du/vIce
246  C     residual vector (rhs) Fu = u/vIceRes  C     residual vector (rhs) Fu = u/vIceRes
247  C     output work vectors wk1, -> input work vector wk2  C     output work vectors wk1, -> input work vector wk2
248    
249           CALL SEAICE_FGMRES_DRIVER(  C     map preconditioner results or Jacobian times vector,
250       I        uIceRes, vIceRes,  C     stored in du/vIce to wk2, for iCode=0, wk2 is set to zero,
251       U        duIce, dvIce, iCode,  C     because du/vIce = 0
252       I        FGMRESeps, iOutFGMRES,           CALL SEAICE_MAP2VEC(nVec,duIce,dvIce,wk2,.TRUE.,myThid)
253       I        newtonIter, krylovIter, myTime, myIter, myThid )  C
254             CALL SEAICE_FGMRES (nVec,im,rhs,sol,ifgmres,krylovIter,
255         U        vv,w,wk1,wk2,
256         I        FGMRESeps,SEAICEkrylovIterMax,iOutFGMRES,
257         U        iCode,
258         I        myThid)
259    C    
260             IF ( iCode .EQ. 0 ) THEN
261    C     map sol(ution) vector to du/vIce
262              CALL SEAICE_MAP2VEC(nVec,duIce,dvIce,sol,.FALSE.,myThid)
263             ELSE
264    C     map work vector to du/vIce to either compute a preconditioner
265    C     solution (wk1=rhs) or a Jacobian times wk1
266              CALL SEAICE_MAP2VEC(nVec,duIce,dvIce,wk1,.FALSE.,myThid)
267             ENDIF
268    C     Fill overlaps in updated fields
269             CALL EXCH_UV_XY_RL( duIce, dvIce,.TRUE.,myThid)
270  C     FGMRES returns iCode either asking for an new preconditioned vector  C     FGMRES returns iCode either asking for an new preconditioned vector
271  C     or product of matrix (Jacobian) times vector. For iCode = 0, terminate  C     or product of matrix (Jacobian) times vector. For iCode = 0, terminate
272  C     iteration  C     iteration
# Line 213  C     Call preconditioner Line 275  C     Call preconditioner
275            IF ( SOLV_MAX_ITERS .GT. 0 )            IF ( SOLV_MAX_ITERS .GT. 0 )
276       &         CALL SEAICE_PRECONDITIONER(       &         CALL SEAICE_PRECONDITIONER(
277       U         duIce, dvIce,       U         duIce, dvIce,
278       I         zetaPre, etaPre, etaZpre, dwatPre,       I         zetaPre, etaPre, etaZpre, zetaZpre, dwatPre,
279       I         newtonIter, krylovIter, myTime, myIter, myThid )       I         newtonIter, krylovIter, myTime, myIter, myThid )
280           ELSEIF (iCode.GE.2) THEN           ELSEIF (iCode.GE.2) THEN
281  C     Compute Jacobian times vector  C     Compute Jacobian times vector

Legend:
Removed from v.1.21  
changed lines
  Added in v.1.29

  ViewVC Help
Powered by ViewVC 1.1.22