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

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

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


Revision 1.28 - (show annotations) (download)
Mon Dec 1 12:31:36 2014 UTC (10 years, 7 months ago) by mlosch
Branch: MAIN
CVS Tags: checkpoint65r, checkpoint65s, checkpoint65p, checkpoint65q, checkpoint65j, checkpoint65k, checkpoint65h, checkpoint65i, checkpoint65n, checkpoint65o, checkpoint65l, checkpoint65m
Changes since 1.27: +4 -2 lines
introduce strongly implicit coupling, intended for stabilizing LSR
(following Hutchings et al. 2004)
  - introduce zetaZ as a global variable (requires adjustments in
    seaice_evp.F and seaice_jfnk.F) and compute analoguously to etaZ
    in seaice_calc_viscosities.F
  - new flag SEAICEuseStrImpCpl (default off)
  - add new terms zetaZ*du/dy and zetaZ*dv/dx on both sides of the
    momentum equations

1 C $Header: /u/gcmpack/MITgcm/pkg/seaice/seaice_jfnk.F,v 1.27 2014/10/20 03:20:57 gforget Exp $
2 C $Name: $
3
4 #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
15 C !ROUTINE: SEAICE_JFNK
16 C !INTERFACE:
17 SUBROUTINE SEAICE_JFNK( myTime, myIter, myThid )
18
19 C !DESCRIPTION: \bv
20 C *==========================================================*
21 C | SUBROUTINE SEAICE_JFNK
22 C | o Ice dynamics using a Jacobian-free Newton-Krylov solver
23 C | following J.-F. Lemieux et al. Improving the numerical
24 C | convergence of viscous-plastic sea ice models with the
25 C | Jacobian-free Newton-Krylov method. J. Comp. Phys. 229,
26 C | 2840-2852 (2010).
27 C | o The logic follows JFs code.
28 C *==========================================================*
29 C | written by Martin Losch, Oct 2012
30 C *==========================================================*
31 C \ev
32
33 C !USES:
34 IMPLICIT NONE
35
36 C === Global variables ===
37 #include "SIZE.h"
38 #include "EEPARAMS.h"
39 #include "PARAMS.h"
40 #include "DYNVARS.h"
41 #include "GRID.h"
42 #include "SEAICE_SIZE.h"
43 #include "SEAICE_PARAMS.h"
44 #include "SEAICE.h"
45
46 #ifdef ALLOW_AUTODIFF_TAMC
47 # include "tamc.h"
48 #endif
49
50 C !INPUT/OUTPUT PARAMETERS:
51 C === Routine arguments ===
52 C myTime :: Simulation time
53 C myIter :: Simulation timestep number
54 C myThid :: my Thread Id. number
55 _RL myTime
56 INTEGER myIter
57 INTEGER myThid
58
59 #ifdef SEAICE_ALLOW_JFNK
60 C !FUNCTIONS:
61 LOGICAL DIFFERENT_MULTIPLE
62 EXTERNAL DIFFERENT_MULTIPLE
63
64 C !LOCAL VARIABLES:
65 C === Local variables ===
66 C i,j,bi,bj :: loop indices
67 INTEGER i,j,bi,bj
68 C loop indices
69 INTEGER newtonIter
70 INTEGER krylovIter, krylovFails
71 INTEGER totalKrylovItersLoc, totalNewtonItersLoc
72 C FGMRES flag that determines amount of output messages of fgmres
73 INTEGER iOutFGMRES
74 C FGMRES flag that indicates what fgmres wants us to do next
75 INTEGER iCode
76 _RL JFNKresidual
77 _RL JFNKresidualKm1
78 C parameters to compute convergence criterion
79 _RL JFNKgamma_lin
80 _RL FGMRESeps
81 _RL JFNKtol
82 C backward differences extrapolation factors
83 _RL bdfFac, bdfAlpha
84 C
85 _RL recip_deltaT
86 LOGICAL JFNKconverged, krylovConverged
87 LOGICAL writeNow
88 CHARACTER*(MAX_LEN_MBUF) msgBuf
89
90 C u/vIceRes :: residual of sea-ice momentum equations
91 _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)
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
97 _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)
99 C precomputed (= constant per Newton iteration) versions of
100 C zeta, eta, and DWATN, press
101 _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)
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)
106 CEOP
107
108 C Initialise
109 newtonIter = 0
110 krylovFails = 0
111 totalKrylovItersLoc = 0
112 JFNKconverged = .FALSE.
113 JFNKtol = 0. _d 0
114 JFNKresidual = 0. _d 0
115 JFNKresidualKm1 = 0. _d 0
116 FGMRESeps = 0. _d 0
117 recip_deltaT = 1. _d 0 / SEAICE_deltaTdyn
118
119 iOutFGMRES=0
120 C with iOutFgmres=1, seaice_fgmres prints the residual at each iteration
121 IF ( debugLevel.GE.debLevC .AND.
122 & DIFFERENT_MULTIPLE( SEAICE_monFreq, myTime, deltaTClock ) )
123 & iOutFGMRES=1
124
125 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)
137 DO bi=myBxLo(myThid),myBxHi(myThid)
138 DO J=1-OLy,sNy+OLy
139 DO I=1-OLx,sNx+OLx
140 uIceRes(I,J,bi,bj) = 0. _d 0
141 vIceRes(I,J,bi,bj) = 0. _d 0
142 duIce (I,J,bi,bj) = 0. _d 0
143 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)
154 vIceNm1(I,J,bi,bj) = vIce(I,J,bi,bj)
155 ENDDO
156 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:
160 C sea-surface tilt and wind stress:
161 C FORCEX/Y0 - mass*(1.5*u/vIceNm1+0.5*(u/vIceNm1-u/vIceNm2))/deltaT
162 DO J=1-OLy,sNy+OLy
163 DO I=1-OLx,sNx+OLx
164 FORCEX(I,J,bi,bj) = FORCEX0(I,J,bi,bj)
165 & + seaiceMassU(I,J,bi,bj)*duIcNm1(I,J,bi,bj)*recip_deltaT
166 FORCEY(I,J,bi,bj) = FORCEY0(I,J,bi,bj)
167 & + seaiceMassV(I,J,bi,bj)*dvIcNm1(I,J,bi,bj)*recip_deltaT
168 ENDDO
169 ENDDO
170 CML ENDIF
171 ENDDO
172 ENDDO
173 C Start nonlinear Newton iteration: outer loop iteration
174 DO WHILE ( newtonIter.LT.SEAICEnewtonIterMax .AND.
175 & .NOT.JFNKconverged )
176 newtonIter = newtonIter + 1
177 C Compute initial residual F(u), (includes computation of global
178 C variables DWATN, zeta, and eta)
179 IF ( newtonIter .EQ. 1 ) CALL SEAICE_JFNK_UPDATE(
180 I duIce, dvIce,
181 U uIce, vIce, JFNKresidual,
182 O uIceRes, vIceRes,
183 I newtonIter, myTime, myIter, myThid )
184 C local copies of precomputed coefficients that are to stay
185 C constant for the preconditioner
186 DO bj=myByLo(myThid),myByHi(myThid)
187 DO bi=myBxLo(myThid),myBxHi(myThid)
188 DO j=1-OLy,sNy+OLy
189 DO i=1-OLx,sNx+OLx
190 zetaPre(I,J,bi,bj) = zeta(I,J,bi,bj)
191 zetaZPre(I,J,bi,bj)= zetaZ(I,J,bi,bj)
192 etaPre(I,J,bi,bj) = eta(I,J,bi,bj)
193 etaZPre(I,J,bi,bj) = etaZ(I,J,bi,bj)
194 dwatPre(I,J,bi,bj) = DWATN(I,J,bi,bj)
195 ENDDO
196 ENDDO
197 ENDDO
198 ENDDO
199 C compute convergence criterion for linear preconditioned FGMRES
200 JFNKgamma_lin = JFNKgamma_lin_max
201 IF ( newtonIter.GT.1.AND.newtonIter.LE.SEAICE_JFNK_tolIter
202 & .AND.JFNKresidual.LT.JFNKres_t ) THEN
203 C Eisenstat and Walker (1996), eq.(2.6)
204 JFNKgamma_lin = SEAICE_JFNKphi
205 & *( JFNKresidual/JFNKresidualKm1 )**SEAICE_JFNKalpha
206 JFNKgamma_lin = min(JFNKgamma_lin_max, JFNKgamma_lin)
207 JFNKgamma_lin = max(JFNKgamma_lin_min, JFNKgamma_lin)
208 ENDIF
209 C save the residual for the next iteration
210 JFNKresidualKm1 = JFNKresidual
211
212 C The Krylov iteration using FGMRES, the preconditioner is LSOR
213 C for now. The code is adapted from SEAICE_LSR, but heavily stripped
214 C down.
215 C krylovIter is mapped into "its" in seaice_fgmres and is incremented
216 C in that routine
217 krylovIter = 0
218 iCode = 0
219
220 JFNKconverged = JFNKresidual.LT.JFNKtol
221
222 C do Krylov loop only if convergence is not reached
223
224 IF ( .NOT.JFNKconverged ) THEN
225
226 C start Krylov iteration (FGMRES)
227
228 krylovConverged = .FALSE.
229 FGMRESeps = JFNKgamma_lin * JFNKresidual
230 DO WHILE ( .NOT.krylovConverged )
231 C solution vector sol = du/vIce
232 C residual vector (rhs) Fu = u/vIceRes
233 C output work vectors wk1, -> input work vector wk2
234
235 CALL SEAICE_FGMRES_DRIVER(
236 I uIceRes, vIceRes,
237 U duIce, dvIce, iCode,
238 I FGMRESeps, iOutFGMRES,
239 I newtonIter, krylovIter, myTime, myIter, myThid )
240 C FGMRES returns iCode either asking for an new preconditioned vector
241 C or product of matrix (Jacobian) times vector. For iCode = 0, terminate
242 C iteration
243 IF (iCode.EQ.1) THEN
244 C Call preconditioner
245 IF ( SOLV_MAX_ITERS .GT. 0 )
246 & CALL SEAICE_PRECONDITIONER(
247 U duIce, dvIce,
248 I zetaPre, etaPre, etaZpre, zetaZpre, dwatPre,
249 I newtonIter, krylovIter, myTime, myIter, myThid )
250 ELSEIF (iCode.GE.2) THEN
251 C Compute Jacobian times vector
252 CALL SEAICE_JACVEC(
253 I uIce, vIce, uIceRes, vIceRes,
254 U duIce, dvIce,
255 I newtonIter, krylovIter, myTime, myIter, myThid )
256 ENDIF
257 krylovConverged = iCode.EQ.0
258 C End of Krylov iterate
259 ENDDO
260 totalKrylovItersLoc = totalKrylovItersLoc + krylovIter
261 C some output diagnostics
262 IF ( debugLevel.GE.debLevA ) THEN
263 _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))')
274 & ' S/R SEAICE_JFNK: Newton iterate / total = ',newtonIter,
275 & ' / ', totalNewtonItersLoc,
276 & ', Nb. of FGMRES iterations = ', krylovIter
277 CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
278 & SQUEEZE_RIGHT, myThid )
279 _END_MASTER( myThid )
280 ENDIF
281 IF ( krylovIter.EQ.SEAICEkrylovIterMax ) THEN
282 krylovFails = krylovFails + 1
283 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
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)
304 DO bi=myBxLo(myThid),myBxHi(myThid)
305 DO J=1-OLy,sNy+OLy
306 DO I=1-OLx,sNx+OLx
307 duIce(I,J,bi,bj)= 0. _d 0
308 dvIce(I,J,bi,bj)= 0. _d 0
309 ENDDO
310 ENDDO
311 ENDDO
312 ENDDO
313 ENDIF
314 C end of Newton iterate
315 ENDDO
316
317 C-- Output diagnostics
318
319 IF ( SEAICE_monFreq .GT. 0. _d 0 ) THEN
320 C Count iterations
321 totalJFNKtimeSteps = totalJFNKtimeSteps + 1
322 totalNewtonIters = totalNewtonIters + newtonIter
323 totalKrylovIters = totalKrylovIters + totalKrylovItersLoc
324 C Record failure
325 totalKrylovFails = totalKrylovFails + krylovFails
326 IF ( newtonIter .EQ. SEAICEnewtonIterMax ) THEN
327 totalNewtonFails = totalNewtonFails + 1
328 ENDIF
329 ENDIF
330 C Decide whether it is time to dump and reset the counter
331 writeNow = DIFFERENT_MULTIPLE(SEAICE_monFreq,
332 & 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 )
343 WRITE(msgBuf,'(A)')
344 &' // ======================================================='
345 CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
346 & SQUEEZE_RIGHT, myThid )
347 WRITE(msgBuf,'(A)') ' // Begin JFNK statistics'
348 CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
349 & SQUEEZE_RIGHT, myThid )
350 WRITE(msgBuf,'(A)')
351 &' // ======================================================='
352 CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
353 & SQUEEZE_RIGHT, myThid )
354 WRITE(msgBuf,'(A,I10)')
355 & ' %JFNK_MON: time step = ', myIter+1
356 CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
357 & SQUEEZE_RIGHT, myThid )
358 WRITE(msgBuf,'(A,I10)')
359 & ' %JFNK_MON: Nb. of time steps = ', totalJFNKtimeSteps
360 CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
361 & SQUEEZE_RIGHT, myThid )
362 WRITE(msgBuf,'(A,I10)')
363 & ' %JFNK_MON: Nb. of Newton steps = ', totalNewtonIters
364 CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
365 & SQUEEZE_RIGHT, myThid )
366 WRITE(msgBuf,'(A,I10)')
367 & ' %JFNK_MON: Nb. of Krylov steps = ', totalKrylovIters
368 CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
369 & SQUEEZE_RIGHT, myThid )
370 WRITE(msgBuf,'(A,I10)')
371 & ' %JFNK_MON: Nb. of Newton failures = ', totalNewtonFails
372 CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
373 & SQUEEZE_RIGHT, myThid )
374 WRITE(msgBuf,'(A,I10)')
375 & ' %JFNK_MON: Nb. of Krylov failures = ', totalKrylovFails
376 CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
377 & SQUEEZE_RIGHT, myThid )
378 WRITE(msgBuf,'(A)')
379 &' // ======================================================='
380 CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
381 & SQUEEZE_RIGHT, myThid )
382 WRITE(msgBuf,'(A)') ' // End JFNK statistics'
383 CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
384 & SQUEEZE_RIGHT, myThid )
385 WRITE(msgBuf,'(A)')
386 &' // ======================================================='
387 CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
388 & SQUEEZE_RIGHT, myThid )
389 _END_MASTER( myThid )
390 C reset and start again
391 totalJFNKtimeSteps = 0
392 totalNewtonIters = 0
393 totalKrylovIters = 0
394 totalKrylovFails = 0
395 totalNewtonFails = 0
396 ENDIF
397
398 C Print more debugging information
399 IF ( debugLevel.GE.debLevA ) THEN
400 IF ( newtonIter .EQ. SEAICEnewtonIterMax ) THEN
401 _BEGIN_MASTER( myThid )
402 WRITE(msgBuf,'(A,I10)')
403 & ' S/R SEAICE_JFNK: JFNK did not converge in timestep ',
404 & myIter+1
405 CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
406 & SQUEEZE_RIGHT, myThid )
407 _END_MASTER( myThid )
408 ENDIF
409 IF ( krylovFails .GT. 0 ) THEN
410 _BEGIN_MASTER( myThid )
411 WRITE(msgBuf,'(A,I4,A,I10)')
412 & ' S/R SEAICE_JFNK: FGMRES did not converge ',
413 & krylovFails, ' times in timestep ', myIter+1
414 CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
415 & SQUEEZE_RIGHT, myThid )
416 _END_MASTER( myThid )
417 ENDIF
418 _BEGIN_MASTER( myThid )
419 WRITE(msgBuf,'(A,I6,A,I10)')
420 & ' S/R SEAICE_JFNK: Total number FGMRES iterations = ',
421 & totalKrylovItersLoc, ' in timestep ', myIter+1
422 CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
423 & SQUEEZE_RIGHT, myThid )
424 _END_MASTER( myThid )
425 ENDIF
426
427 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
565 END

  ViewVC Help
Powered by ViewVC 1.1.22