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 |
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 |
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 |
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 |
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 |
94 |
CHARACTER*(MAX_LEN_MBUF) msgBuf |
CHARACTER*(MAX_LEN_MBUF) msgBuf |
95 |
C |
|
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 vector version of the residuals |
C extra time level required for backward difference time stepping |
100 |
_RL resTmp (nVec,1,nSx,nSy) |
_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 |
132 |
& DIFFERENT_MULTIPLE( SEAICE_monFreq, myTime, deltaTClock ) ) |
& DIFFERENT_MULTIPLE( SEAICE_monFreq, myTime, deltaTClock ) ) |
133 |
& iOutFGMRES=1 |
& iOutFGMRES=1 |
134 |
|
|
135 |
C |
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 |
149 |
DO I=1-Olx,sNx+Olx |
DO I=1-OLx,sNx+OLx |
150 |
uIceRes(I,J,bi,bj) = 0. _d 0 |
uIceRes(I,J,bi,bj) = 0. _d 0 |
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 |
184 |
DO WHILE ( newtonIter.LT.SEAICEnewtonIterMax .AND. |
DO WHILE ( newtonIter.LT.SEAICEnonLinIterMax .AND. |
185 |
& .NOT.JFNKconverged ) |
& .NOT.JFNKconverged ) |
186 |
newtonIter = newtonIter + 1 |
newtonIter = newtonIter + 1 |
187 |
C Compute initial residual F(u), (includes computation of global |
C Compute initial residual F(u), (includes computation of global |
188 |
C variables DWATN, zeta, and eta) |
C variables DWATN, zeta, and eta) |
189 |
IF ( newtonIter .EQ. 1 ) CALL SEAICE_JFNK_UPDATE( |
IF ( newtonIter .EQ. 1 ) CALL SEAICE_JFNK_UPDATE( |
190 |
I duIce, dvIce, |
I duIce, dvIce, |
191 |
U uIce, vIce, JFNKresidual, |
U uIce, vIce, JFNKresidual, |
192 |
O uIceRes, vIceRes, |
O uIceRes, vIceRes, |
193 |
I newtonIter, myTime, myIter, myThid ) |
I newtonIter, myTime, myIter, myThid ) |
195 |
C constant for the preconditioner |
C constant for the preconditioner |
196 |
DO bj=myByLo(myThid),myByHi(myThid) |
DO bj=myByLo(myThid),myByHi(myThid) |
197 |
DO bi=myBxLo(myThid),myBxHi(myThid) |
DO bi=myBxLo(myThid),myBxHi(myThid) |
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) |
208 |
ENDDO |
ENDDO |
209 |
C compute convergence criterion for linear preconditioned FGMRES |
C compute convergence criterion for linear preconditioned FGMRES |
210 |
JFNKgamma_lin = JFNKgamma_lin_max |
JFNKgamma_lin = JFNKgamma_lin_max |
211 |
IF ( newtonIter.GT.1.AND.newtonIter.LE.100 |
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 |
219 |
C save the residual for the next iteration |
C save the residual for the next iteration |
220 |
JFNKresidualKm1 = JFNKresidual |
JFNKresidualKm1 = JFNKresidual |
221 |
C |
|
222 |
C The Krylov iteration using FGMRES, the preconditioner is LSOR |
C The Krylov iteration using FGMRES, the preconditioner is LSOR |
223 |
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 |
224 |
C down. |
C down. |
226 |
C in that routine |
C in that routine |
227 |
krylovIter = 0 |
krylovIter = 0 |
228 |
iCode = 0 |
iCode = 0 |
229 |
C |
|
230 |
JFNKconverged = JFNKresidual.LT.JFNKtol |
JFNKconverged = JFNKresidual.LT.JFNKtol |
231 |
C |
& .OR.JFNKresidual.EQ.0. _d 0 |
232 |
|
|
233 |
C do Krylov loop only if convergence is not reached |
C do Krylov loop only if convergence is not reached |
234 |
C |
|
235 |
IF ( .NOT.JFNKconverged ) THEN |
IF ( .NOT.JFNKconverged ) THEN |
236 |
C |
|
237 |
C start Krylov iteration (FGMRES) |
C start Krylov iteration (FGMRES) |
238 |
C |
|
239 |
krylovConverged = .FALSE. |
krylovConverged = .FALSE. |
240 |
FGMRESeps = JFNKgamma_lin * JFNKresidual |
FGMRESeps = JFNKgamma_lin * JFNKresidual |
241 |
DO WHILE ( .NOT.krylovConverged ) |
C map first guess sol; it is zero because the solution is a correction |
242 |
|
CALL SEAICE_MAP2VEC(nVec,duIce,dvIce,sol,.TRUE.,myThid) |
243 |
|
C map rhs and change its sign because we are solving J*u = -F |
244 |
|
CALL SEAICE_MAP2VEC(nVec,uIceRes,vIceRes,rhs,.TRUE.,myThid) |
245 |
|
DO bj=myByLo(myThid),myByHi(myThid) |
246 |
|
DO bi=myBxLo(myThid),myBxHi(myThid) |
247 |
|
DO j=1,nVec |
248 |
|
rhs(j,bi,bj) = - rhs(j,bi,bj) |
249 |
|
ENDDO |
250 |
|
ENDDO |
251 |
|
ENDDO |
252 |
|
DO WHILE ( .NOT.krylovConverged ) |
253 |
C solution vector sol = du/vIce |
C solution vector sol = du/vIce |
254 |
C residual vector (rhs) Fu = u/vIceRes |
C residual vector (rhs) Fu = u/vIceRes |
255 |
C output work vectors wk1, -> input work vector wk2 |
C output work vectors wk1, -> input work vector wk2 |
256 |
|
|
257 |
|
C map preconditioner results or Jacobian times vector, |
258 |
|
C stored in du/vIce to wk2, for iCode=0, wk2 is set to zero, |
259 |
|
C because du/vIce = 0 |
260 |
|
CALL SEAICE_MAP2VEC(nVec,duIce,dvIce,wk2,.TRUE.,myThid) |
261 |
|
C |
262 |
|
CALL SEAICE_FGMRES (nVec,im,rhs,sol,ifgmres,krylovIter, |
263 |
|
U vv,w,wk1,wk2, |
264 |
|
I FGMRESeps,SEAICElinearIterMax,iOutFGMRES, |
265 |
|
U iCode, |
266 |
|
I myThid) |
267 |
C |
C |
268 |
CALL SEAICE_FGMRES_DRIVER( |
IF ( iCode .EQ. 0 ) THEN |
269 |
I uIceRes, vIceRes, |
C map sol(ution) vector to du/vIce |
270 |
U duIce, dvIce, iCode, |
CALL SEAICE_MAP2VEC(nVec,duIce,dvIce,sol,.FALSE.,myThid) |
271 |
I FGMRESeps, iOutFGMRES, |
ELSE |
272 |
I newtonIter, krylovIter, myTime, myIter, myThid ) |
C map work vector to du/vIce to either compute a preconditioner |
273 |
|
C solution (wk1=rhs) or a Jacobian times wk1 |
274 |
|
CALL SEAICE_MAP2VEC(nVec,duIce,dvIce,wk1,.FALSE.,myThid) |
275 |
|
ENDIF |
276 |
|
C Fill overlaps in updated fields |
277 |
|
CALL EXCH_UV_XY_RL( duIce, dvIce,.TRUE.,myThid) |
278 |
C FGMRES returns iCode either asking for an new preconditioned vector |
C FGMRES returns iCode either asking for an new preconditioned vector |
279 |
C or product of matrix (Jacobian) times vector. For iCode = 0, terminate |
C or product of matrix (Jacobian) times vector. For iCode = 0, terminate |
280 |
C iteration |
C iteration |
281 |
IF (iCode.EQ.1) THEN |
IF (iCode.EQ.1) THEN |
282 |
C Call preconditioner |
C Call preconditioner |
283 |
IF ( SOLV_MAX_ITERS .GT. 0 ) |
IF ( SEAICEpreconLinIter .GT. 0 ) |
284 |
& CALL SEAICE_PRECONDITIONER( |
& CALL SEAICE_PRECONDITIONER( |
285 |
U duIce, dvIce, |
U duIce, dvIce, |
286 |
I zetaPre, etaPre, etaZpre, dwatPre, |
I zetaPre, etaPre, etaZpre, zetaZpre, dwatPre, |
287 |
I newtonIter, krylovIter, myTime, myIter, myThid ) |
I newtonIter, krylovIter, myTime, myIter, myThid ) |
288 |
ELSEIF (iCode.GE.2) THEN |
ELSEIF (iCode.GE.2) THEN |
289 |
C Compute Jacobian times vector |
C Compute Jacobian times vector |
290 |
CALL SEAICE_JACVEC( |
CALL SEAICE_JACVEC( |
291 |
I uIce, vIce, uIceRes, vIceRes, |
I uIce, vIce, uIceRes, vIceRes, |
292 |
U duIce, dvIce, |
U duIce, dvIce, |
293 |
I newtonIter, krylovIter, myTime, myIter, myThid ) |
I newtonIter, krylovIter, myTime, myIter, myThid ) |
294 |
ENDIF |
ENDIF |
295 |
krylovConverged = iCode.EQ.0 |
krylovConverged = iCode.EQ.0 |
299 |
C some output diagnostics |
C some output diagnostics |
300 |
IF ( debugLevel.GE.debLevA ) THEN |
IF ( debugLevel.GE.debLevA ) THEN |
301 |
_BEGIN_MASTER( myThid ) |
_BEGIN_MASTER( myThid ) |
302 |
totalNewtonItersLoc = |
totalNewtonItersLoc = |
303 |
& SEAICEnewtonIterMax*(myIter-nIter0)+newtonIter |
& SEAICEnonLinIterMax*(myIter-nIter0)+newtonIter |
304 |
WRITE(msgBuf,'(2A,2(1XI6),2E12.5)') |
WRITE(msgBuf,'(2A,2(1XI6),2E12.5)') |
305 |
& ' S/R SEAICE_JFNK: Newton iterate / total, ', |
& ' S/R SEAICE_JFNK: Newton iterate / total, ', |
306 |
& 'JFNKgamma_lin, initial norm = ', |
& 'JFNKgamma_lin, initial norm = ', |
307 |
& newtonIter, totalNewtonItersLoc, |
& newtonIter, totalNewtonItersLoc, |
309 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
310 |
& SQUEEZE_RIGHT, myThid ) |
& SQUEEZE_RIGHT, myThid ) |
311 |
WRITE(msgBuf,'(3(A,I6))') |
WRITE(msgBuf,'(3(A,I6))') |
312 |
& ' S/R SEAICE_JFNK: Newton iterate / total = ',newtonIter, |
& ' S/R SEAICE_JFNK: Newton iterate / total = ',newtonIter, |
313 |
& ' / ', totalNewtonItersLoc, |
& ' / ', totalNewtonItersLoc, |
314 |
& ', Nb. of FGMRES iterations = ', krylovIter |
& ', Nb. of FGMRES iterations = ', krylovIter |
315 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
316 |
& SQUEEZE_RIGHT, myThid ) |
& SQUEEZE_RIGHT, myThid ) |
317 |
_END_MASTER( myThid ) |
_END_MASTER( myThid ) |
318 |
ENDIF |
ENDIF |
319 |
IF ( krylovIter.EQ.SEAICEkrylovIterMax ) THEN |
IF ( krylovIter.EQ.SEAICElinearIterMax ) THEN |
320 |
krylovFails = krylovFails + 1 |
krylovFails = krylovFails + 1 |
321 |
ENDIF |
ENDIF |
322 |
C Set the stopping criterion for the Newton iteration and the |
C Set the stopping criterion for the Newton iteration and the |
323 |
C criterion for the transition from accurate to approximate FGMRES |
C criterion for the transition from accurate to approximate FGMRES |
324 |
IF ( newtonIter .EQ. 1 ) THEN |
IF ( newtonIter .EQ. 1 ) THEN |
325 |
JFNKtol=JFNKgamma_nonlin*JFNKresidual |
JFNKtol=SEAICEnonLinTol*JFNKresidual |
326 |
IF ( JFNKres_tFac .NE. UNSET_RL ) |
IF ( JFNKres_tFac .NE. UNSET_RL ) |
327 |
& JFNKres_t = JFNKresidual * JFNKres_tFac |
& JFNKres_t = JFNKresidual * JFNKres_tFac |
328 |
ENDIF |
ENDIF |
332 |
C at the beginning of the Newton iteration, thereby saving us from |
C at the beginning of the Newton iteration, thereby saving us from |
333 |
C the extra call of seaice_jfnk_update, but unfortunately that |
C the extra call of seaice_jfnk_update, but unfortunately that |
334 |
C changes the results, so we leave the stuff here for now. |
C changes the results, so we leave the stuff here for now. |
335 |
CALL SEAICE_JFNK_UPDATE( |
CALL SEAICE_JFNK_UPDATE( |
336 |
I duIce, dvIce, |
I duIce, dvIce, |
337 |
U uIce, vIce, JFNKresidual, |
U uIce, vIce, JFNKresidual, |
338 |
O uIceRes, vIceRes, |
O uIceRes, vIceRes, |
339 |
I newtonIter, myTime, myIter, myThid ) |
I newtonIter, myTime, myIter, myThid ) |
340 |
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 |
341 |
DO bj=myByLo(myThid),myByHi(myThid) |
DO bj=myByLo(myThid),myByHi(myThid) |
342 |
DO bi=myBxLo(myThid),myBxHi(myThid) |
DO bi=myBxLo(myThid),myBxHi(myThid) |
343 |
DO J=1-Oly,sNy+Oly |
DO J=1-OLy,sNy+OLy |
344 |
DO I=1-Olx,sNx+Olx |
DO I=1-OLx,sNx+OLx |
345 |
duIce(I,J,bi,bj)= 0. _d 0 |
duIce(I,J,bi,bj)= 0. _d 0 |
346 |
dvIce(I,J,bi,bj)= 0. _d 0 |
dvIce(I,J,bi,bj)= 0. _d 0 |
347 |
ENDDO |
ENDDO |
351 |
ENDIF |
ENDIF |
352 |
C end of Newton iterate |
C end of Newton iterate |
353 |
ENDDO |
ENDDO |
354 |
C |
|
355 |
C-- Output diagnostics |
C-- Output diagnostics |
356 |
C |
|
357 |
IF ( SEAICE_monFreq .GT. 0. _d 0 ) THEN |
IF ( SEAICE_monFreq .GT. 0. _d 0 ) THEN |
358 |
C Count iterations |
C Count iterations |
359 |
totalJFNKtimeSteps = totalJFNKtimeSteps + 1 |
totalJFNKtimeSteps = totalJFNKtimeSteps + 1 |
361 |
totalKrylovIters = totalKrylovIters + totalKrylovItersLoc |
totalKrylovIters = totalKrylovIters + totalKrylovItersLoc |
362 |
C Record failure |
C Record failure |
363 |
totalKrylovFails = totalKrylovFails + krylovFails |
totalKrylovFails = totalKrylovFails + krylovFails |
364 |
IF ( newtonIter .EQ. SEAICEnewtonIterMax ) THEN |
IF ( newtonIter .EQ. SEAICEnonLinIterMax ) THEN |
365 |
totalNewtonFails = totalNewtonFails + 1 |
totalNewtonFails = totalNewtonFails + 1 |
366 |
ENDIF |
ENDIF |
367 |
ENDIF |
ENDIF |
368 |
C Decide whether it is time to dump and reset the counter |
C Decide whether it is time to dump and reset the counter |
369 |
writeNow = DIFFERENT_MULTIPLE(SEAICE_monFreq, |
writeNow = DIFFERENT_MULTIPLE(SEAICE_monFreq, |
370 |
& myTime+deltaTClock, deltaTClock) |
& myTime+deltaTClock, deltaTClock) |
371 |
#ifdef ALLOW_CAL |
#ifdef ALLOW_CAL |
372 |
IF ( useCAL ) THEN |
IF ( useCAL ) THEN |
373 |
CALL CAL_TIME2DUMP( |
CALL CAL_TIME2DUMP( |
374 |
I zeroRL, SEAICE_monFreq, deltaTClock, |
I zeroRL, SEAICE_monFreq, deltaTClock, |
375 |
U writeNow, |
U writeNow, |
376 |
I myTime+deltaTclock, myIter+1, myThid ) |
I myTime+deltaTclock, myIter+1, myThid ) |
378 |
#endif |
#endif |
379 |
IF ( writeNow ) THEN |
IF ( writeNow ) THEN |
380 |
_BEGIN_MASTER( myThid ) |
_BEGIN_MASTER( myThid ) |
381 |
WRITE(msgBuf,'(A)') |
WRITE(msgBuf,'(A)') |
382 |
&' // =======================================================' |
&' // =======================================================' |
383 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
384 |
& SQUEEZE_RIGHT, myThid ) |
& SQUEEZE_RIGHT, myThid ) |
385 |
WRITE(msgBuf,'(A)') ' // Begin JFNK statistics' |
WRITE(msgBuf,'(A)') ' // Begin JFNK statistics' |
386 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
387 |
& SQUEEZE_RIGHT, myThid ) |
& SQUEEZE_RIGHT, myThid ) |
388 |
WRITE(msgBuf,'(A)') |
WRITE(msgBuf,'(A)') |
389 |
&' // =======================================================' |
&' // =======================================================' |
390 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
391 |
& SQUEEZE_RIGHT, myThid ) |
& SQUEEZE_RIGHT, myThid ) |
392 |
WRITE(msgBuf,'(A,I10)') |
WRITE(msgBuf,'(A,I10)') |
393 |
& ' %JFNK_MON: time step = ', myIter+1 |
& ' %JFNK_MON: time step = ', myIter+1 |
394 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
395 |
& SQUEEZE_RIGHT, myThid ) |
& SQUEEZE_RIGHT, myThid ) |
396 |
WRITE(msgBuf,'(A,I10)') |
WRITE(msgBuf,'(A,I10)') |
397 |
& ' %JFNK_MON: Nb. of time steps = ', totalJFNKtimeSteps |
& ' %JFNK_MON: Nb. of time steps = ', totalJFNKtimeSteps |
398 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
399 |
& SQUEEZE_RIGHT, myThid ) |
& SQUEEZE_RIGHT, myThid ) |
400 |
WRITE(msgBuf,'(A,I10)') |
WRITE(msgBuf,'(A,I10)') |
401 |
& ' %JFNK_MON: Nb. of Newton steps = ', totalNewtonIters |
& ' %JFNK_MON: Nb. of Newton steps = ', totalNewtonIters |
402 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
403 |
& SQUEEZE_RIGHT, myThid ) |
& SQUEEZE_RIGHT, myThid ) |
404 |
WRITE(msgBuf,'(A,I10)') |
WRITE(msgBuf,'(A,I10)') |
405 |
& ' %JFNK_MON: Nb. of Krylov steps = ', totalKrylovIters |
& ' %JFNK_MON: Nb. of Krylov steps = ', totalKrylovIters |
406 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
407 |
& SQUEEZE_RIGHT, myThid ) |
& SQUEEZE_RIGHT, myThid ) |
408 |
WRITE(msgBuf,'(A,I10)') |
WRITE(msgBuf,'(A,I10)') |
409 |
& ' %JFNK_MON: Nb. of Newton failures = ', totalNewtonFails |
& ' %JFNK_MON: Nb. of Newton failures = ', totalNewtonFails |
410 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
411 |
& SQUEEZE_RIGHT, myThid ) |
& SQUEEZE_RIGHT, myThid ) |
412 |
WRITE(msgBuf,'(A,I10)') |
WRITE(msgBuf,'(A,I10)') |
413 |
& ' %JFNK_MON: Nb. of Krylov failures = ', totalKrylovFails |
& ' %JFNK_MON: Nb. of Krylov failures = ', totalKrylovFails |
414 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
415 |
& SQUEEZE_RIGHT, myThid ) |
& SQUEEZE_RIGHT, myThid ) |
416 |
WRITE(msgBuf,'(A)') |
WRITE(msgBuf,'(A)') |
417 |
&' // =======================================================' |
&' // =======================================================' |
418 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
419 |
& SQUEEZE_RIGHT, myThid ) |
& SQUEEZE_RIGHT, myThid ) |
420 |
WRITE(msgBuf,'(A)') ' // End JFNK statistics' |
WRITE(msgBuf,'(A)') ' // End JFNK statistics' |
421 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
422 |
& SQUEEZE_RIGHT, myThid ) |
& SQUEEZE_RIGHT, myThid ) |
423 |
WRITE(msgBuf,'(A)') |
WRITE(msgBuf,'(A)') |
424 |
&' // =======================================================' |
&' // =======================================================' |
425 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
426 |
& SQUEEZE_RIGHT, myThid ) |
& SQUEEZE_RIGHT, myThid ) |
435 |
|
|
436 |
C Print more debugging information |
C Print more debugging information |
437 |
IF ( debugLevel.GE.debLevA ) THEN |
IF ( debugLevel.GE.debLevA ) THEN |
438 |
IF ( newtonIter .EQ. SEAICEnewtonIterMax ) THEN |
IF ( newtonIter .EQ. SEAICEnonLinIterMax ) THEN |
439 |
_BEGIN_MASTER( myThid ) |
_BEGIN_MASTER( myThid ) |
440 |
WRITE(msgBuf,'(A,I10)') |
WRITE(msgBuf,'(A,I10)') |
441 |
& ' S/R SEAICE_JFNK: JFNK did not converge in timestep ', |
& ' S/R SEAICE_JFNK: JFNK did not converge in timestep ', |
442 |
& myIter+1 |
& myIter+1 |
443 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
446 |
ENDIF |
ENDIF |
447 |
IF ( krylovFails .GT. 0 ) THEN |
IF ( krylovFails .GT. 0 ) THEN |
448 |
_BEGIN_MASTER( myThid ) |
_BEGIN_MASTER( myThid ) |
449 |
WRITE(msgBuf,'(A,I4,A,I10)') |
WRITE(msgBuf,'(A,I4,A,I10)') |
450 |
& ' S/R SEAICE_JFNK: FGMRES did not converge ', |
& ' S/R SEAICE_JFNK: FGMRES did not converge ', |
451 |
& krylovFails, ' times in timestep ', myIter+1 |
& krylovFails, ' times in timestep ', myIter+1 |
452 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
454 |
_END_MASTER( myThid ) |
_END_MASTER( myThid ) |
455 |
ENDIF |
ENDIF |
456 |
_BEGIN_MASTER( myThid ) |
_BEGIN_MASTER( myThid ) |
457 |
WRITE(msgBuf,'(A,I6,A,I10)') |
WRITE(msgBuf,'(A,I6,A,I10)') |
458 |
& ' S/R SEAICE_JFNK: Total number FGMRES iterations = ', |
& ' S/R SEAICE_JFNK: Total number FGMRES iterations = ', |
459 |
& totalKrylovItersLoc, ' in timestep ', myIter+1 |
& totalKrylovItersLoc, ' in timestep ', myIter+1 |
460 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
470 |
C !ROUTINE: SEAICE_JFNK_UPDATE |
C !ROUTINE: SEAICE_JFNK_UPDATE |
471 |
C !INTERFACE: |
C !INTERFACE: |
472 |
|
|
473 |
SUBROUTINE SEAICE_JFNK_UPDATE( |
SUBROUTINE SEAICE_JFNK_UPDATE( |
474 |
I duIce, dvIce, |
I duIce, dvIce, |
475 |
U uIce, vIce, JFNKresidual, |
U uIce, vIce, JFNKresidual, |
476 |
O uIceRes, vIceRes, |
O uIceRes, vIceRes, |
477 |
I newtonIter, myTime, myIter, myThid ) |
I newtonIter, myTime, myIter, myThid ) |
530 |
_RL resLoc, facLS |
_RL resLoc, facLS |
531 |
LOGICAL doLineSearch |
LOGICAL doLineSearch |
532 |
C nVec :: size of the input vector(s) |
C nVec :: size of the input vector(s) |
533 |
C vector version of the residuals |
C resTmp :: vector version of the residuals |
534 |
INTEGER nVec |
INTEGER nVec |
535 |
PARAMETER ( nVec = 2*sNx*sNy ) |
PARAMETER ( nVec = 2*sNx*sNy ) |
536 |
_RL resTmp (nVec,1,nSx,nSy) |
_RL resTmp (nVec,1,nSx,nSy) |
537 |
C |
|
538 |
CHARACTER*(MAX_LEN_MBUF) msgBuf |
CHARACTER*(MAX_LEN_MBUF) msgBuf |
539 |
CEOP |
CEOP |
540 |
|
|
544 |
facLS = 1. _d 0 |
facLS = 1. _d 0 |
545 |
doLineSearch = .TRUE. |
doLineSearch = .TRUE. |
546 |
DO WHILE ( doLineSearch ) |
DO WHILE ( doLineSearch ) |
|
C Determine, if we need more iterations |
|
|
doLineSearch = resLoc .GE. JFNKresidual |
|
|
C Limit the maximum number of iterations arbitrarily to four |
|
|
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 |
|
547 |
C Create update |
C Create update |
548 |
DO bj=myByLo(myThid),myByHi(myThid) |
DO bj=myByLo(myThid),myByHi(myThid) |
549 |
DO bi=myBxLo(myThid),myBxHi(myThid) |
DO bi=myBxLo(myThid),myBxHi(myThid) |
550 |
DO J=1-Oly,sNy+Oly |
DO J=1-OLy,sNy+OLy |
551 |
DO I=1-Olx,sNx+Olx |
DO I=1-OLx,sNx+OLx |
552 |
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) |
553 |
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) |
554 |
ENDDO |
ENDDO |
557 |
ENDDO |
ENDDO |
558 |
C Compute current residual F(u), (includes re-computation of global |
C Compute current residual F(u), (includes re-computation of global |
559 |
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) |
560 |
CALL SEAICE_CALC_RESIDUAL( |
CALL SEAICE_CALC_RESIDUAL( |
561 |
I uIce, vIce, |
I uIce, vIce, |
562 |
O uIceRes, vIceRes, |
O uIceRes, vIceRes, |
563 |
I newtonIter, 0, myTime, myIter, myThid ) |
I newtonIter, 0, myTime, myIter, myThid ) |
564 |
C Important: Compute the norm of the residual using the same scalar |
C Important: Compute the norm of the residual using the same scalar |
565 |
C product that SEAICE_FGMRES does |
C product that SEAICE_FGMRES does |
566 |
CALL SEAICE_MAP2VEC(nVec,uIceRes,vIceRes,resTmp,.TRUE.,myThid) |
CALL SEAICE_MAP2VEC(nVec,uIceRes,vIceRes,resTmp,.TRUE.,myThid) |
567 |
CALL SEAICE_SCALPROD(nVec,1,1,1,resTmp,resTmp,resLoc,myThid) |
CALL SEAICE_SCALPROD(nVec,1,1,1,resTmp,resTmp,resLoc,myThid) |
568 |
resLoc = SQRT(resLoc) |
resLoc = SQRT(resLoc) |
569 |
|
C Determine, if we need more iterations |
570 |
|
doLineSearch = resLoc .GE. JFNKresidual |
571 |
|
C Limit the maximum number of iterations arbitrarily to four |
572 |
|
doLineSearch = doLineSearch .AND. l .LT. 4 |
573 |
|
C For the first iteration du/vIce = 0 and there will be no |
574 |
|
C improvement of the residual possible, so we do only the first |
575 |
|
C iteration |
576 |
|
IF ( newtonIter .EQ. 1 ) doLineSearch = .FALSE. |
577 |
|
C Only start a linesearch after some Newton iterations |
578 |
|
IF ( newtonIter .LE. SEAICE_JFNK_lsIter ) doLineSearch = .FALSE. |
579 |
|
C Increment counter |
580 |
|
l = l + 1 |
581 |
C some output diagnostics |
C some output diagnostics |
582 |
IF ( debugLevel.GE.debLevA .AND. doLineSearch ) THEN |
IF ( debugLevel.GE.debLevA .AND. doLineSearch ) THEN |
583 |
_BEGIN_MASTER( myThid ) |
_BEGIN_MASTER( myThid ) |
584 |
WRITE(msgBuf,'(2A,2(1XI6),3E12.5)') |
WRITE(msgBuf,'(2A,2(1XI6),3E12.5)') |
585 |
& ' S/R SEAICE_JFNK_UPDATE: Newton iter, LSiter, ', |
& ' S/R SEAICE_JFNK_UPDATE: Newton iter, LSiter, ', |
586 |
& 'facLS, JFNKresidual, resLoc = ', |
& 'facLS, JFNKresidual, resLoc = ', |
587 |
& newtonIter, l, facLS, JFNKresidual, resLoc |
& newtonIter, l, facLS, JFNKresidual, resLoc |
597 |
C This is the new residual |
C This is the new residual |
598 |
JFNKresidual = resLoc |
JFNKresidual = resLoc |
599 |
|
|
600 |
#endif /* SEAICE_ALLOW_DYNAMICS and SEAICE_CGRID and SEAICE_ALLOW_JFNK */ |
#endif /* SEAICE_ALLOW_JFNK */ |
601 |
|
|
602 |
RETURN |
RETURN |
603 |
END |
END |