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