1 |
mlosch |
1.28 |
C $Header: /u/gcmpack/MITgcm/pkg/seaice/seaice_jfnk.F,v 1.27 2014/10/20 03:20:57 gforget Exp $ |
2 |
mlosch |
1.1 |
C $Name: $ |
3 |
|
|
|
4 |
|
|
#include "SEAICE_OPTIONS.h" |
5 |
gforget |
1.27 |
#ifdef ALLOW_AUTODIFF |
6 |
|
|
# include "AUTODIFF_OPTIONS.h" |
7 |
|
|
#endif |
8 |
mlosch |
1.1 |
|
9 |
mlosch |
1.15 |
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 |
mlosch |
1.1 |
CBOP |
15 |
|
|
C !ROUTINE: SEAICE_JFNK |
16 |
|
|
C !INTERFACE: |
17 |
|
|
SUBROUTINE SEAICE_JFNK( myTime, myIter, myThid ) |
18 |
|
|
|
19 |
|
|
C !DESCRIPTION: \bv |
20 |
|
|
C *==========================================================* |
21 |
mlosch |
1.15 |
C | SUBROUTINE SEAICE_JFNK |
22 |
mlosch |
1.1 |
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 |
mlosch |
1.21 |
#ifdef SEAICE_ALLOW_JFNK |
60 |
mlosch |
1.5 |
C !FUNCTIONS: |
61 |
|
|
LOGICAL DIFFERENT_MULTIPLE |
62 |
|
|
EXTERNAL DIFFERENT_MULTIPLE |
63 |
mlosch |
1.1 |
|
64 |
mlosch |
1.16 |
C !LOCAL VARIABLES: |
65 |
|
|
C === Local variables === |
66 |
mlosch |
1.1 |
C i,j,bi,bj :: loop indices |
67 |
|
|
INTEGER i,j,bi,bj |
68 |
|
|
C loop indices |
69 |
mlosch |
1.5 |
INTEGER newtonIter |
70 |
|
|
INTEGER krylovIter, krylovFails |
71 |
mlosch |
1.13 |
INTEGER totalKrylovItersLoc, totalNewtonItersLoc |
72 |
mlosch |
1.5 |
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 |
mlosch |
1.1 |
INTEGER iCode |
76 |
mlosch |
1.13 |
_RL JFNKresidual |
77 |
mlosch |
1.1 |
_RL JFNKresidualKm1 |
78 |
|
|
C parameters to compute convergence criterion |
79 |
mlosch |
1.22 |
_RL JFNKgamma_lin |
80 |
mlosch |
1.1 |
_RL FGMRESeps |
81 |
|
|
_RL JFNKtol |
82 |
mlosch |
1.24 |
C backward differences extrapolation factors |
83 |
|
|
_RL bdfFac, bdfAlpha |
84 |
mlosch |
1.23 |
C |
85 |
mlosch |
1.1 |
_RL recip_deltaT |
86 |
|
|
LOGICAL JFNKconverged, krylovConverged |
87 |
mlosch |
1.9 |
LOGICAL writeNow |
88 |
mlosch |
1.1 |
CHARACTER*(MAX_LEN_MBUF) msgBuf |
89 |
jmc |
1.20 |
|
90 |
mlosch |
1.1 |
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 |
mlosch |
1.24 |
C extra time level required for backward difference time stepping |
94 |
mlosch |
1.23 |
_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 |
mlosch |
1.1 |
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 |
jmc |
1.20 |
C precomputed (= constant per Newton iteration) versions of |
100 |
mlosch |
1.2 |
C zeta, eta, and DWATN, press |
101 |
|
|
_RL zetaPre (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy) |
102 |
mlosch |
1.28 |
_RL zetaZPre(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy) |
103 |
mlosch |
1.2 |
_RL etaPre (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy) |
104 |
mlosch |
1.8 |
_RL etaZPre (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy) |
105 |
mlosch |
1.2 |
_RL dwatPre (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy) |
106 |
mlosch |
1.1 |
CEOP |
107 |
|
|
|
108 |
|
|
C Initialise |
109 |
mlosch |
1.5 |
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 |
mlosch |
1.12 |
C with iOutFgmres=1, seaice_fgmres prints the residual at each iteration |
121 |
|
|
IF ( debugLevel.GE.debLevC .AND. |
122 |
mlosch |
1.5 |
& DIFFERENT_MULTIPLE( SEAICE_monFreq, myTime, deltaTClock ) ) |
123 |
|
|
& iOutFGMRES=1 |
124 |
|
|
|
125 |
mlosch |
1.24 |
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 |
mlosch |
1.23 |
ELSE |
131 |
mlosch |
1.24 |
bdfFac = 0.5 _d 0 |
132 |
mlosch |
1.23 |
ENDIF |
133 |
|
|
ENDIF |
134 |
mlosch |
1.24 |
bdfAlpha = 1. _d 0 + bdfFac |
135 |
mlosch |
1.23 |
|
136 |
mlosch |
1.1 |
DO bj=myByLo(myThid),myByHi(myThid) |
137 |
|
|
DO bi=myBxLo(myThid),myBxHi(myThid) |
138 |
jmc |
1.20 |
DO J=1-OLy,sNy+OLy |
139 |
|
|
DO I=1-OLx,sNx+OLx |
140 |
mlosch |
1.1 |
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 |
mlosch |
1.23 |
ENDDO |
145 |
|
|
ENDDO |
146 |
|
|
C cycle ice velocities |
147 |
|
|
DO J=1-OLy,sNy+OLy |
148 |
|
|
DO I=1-OLx,sNx+OLx |
149 |
mlosch |
1.24 |
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 |
mlosch |
1.1 |
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 |
mlosch |
1.26 |
C As long as IMEX is not properly implemented leave this commented out |
158 |
|
|
CML IF ( .NOT.SEAICEuseIMEX ) THEN |
159 |
mlosch |
1.1 |
C Compute things that do no change during the Newton iteration: |
160 |
jmc |
1.20 |
C sea-surface tilt and wind stress: |
161 |
mlosch |
1.25 |
C FORCEX/Y0 - mass*(1.5*u/vIceNm1+0.5*(u/vIceNm1-u/vIceNm2))/deltaT |
162 |
jmc |
1.20 |
DO J=1-OLy,sNy+OLy |
163 |
|
|
DO I=1-OLx,sNx+OLx |
164 |
mlosch |
1.1 |
FORCEX(I,J,bi,bj) = FORCEX0(I,J,bi,bj) |
165 |
mlosch |
1.23 |
& + seaiceMassU(I,J,bi,bj)*duIcNm1(I,J,bi,bj)*recip_deltaT |
166 |
mlosch |
1.1 |
FORCEY(I,J,bi,bj) = FORCEY0(I,J,bi,bj) |
167 |
mlosch |
1.23 |
& + seaiceMassV(I,J,bi,bj)*dvIcNm1(I,J,bi,bj)*recip_deltaT |
168 |
mlosch |
1.1 |
ENDDO |
169 |
|
|
ENDDO |
170 |
mlosch |
1.26 |
CML ENDIF |
171 |
mlosch |
1.1 |
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 |
jmc |
1.20 |
IF ( newtonIter .EQ. 1 ) CALL SEAICE_JFNK_UPDATE( |
180 |
|
|
I duIce, dvIce, |
181 |
mlosch |
1.15 |
U uIce, vIce, JFNKresidual, |
182 |
|
|
O uIceRes, vIceRes, |
183 |
|
|
I newtonIter, myTime, myIter, myThid ) |
184 |
mlosch |
1.1 |
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 |
jmc |
1.20 |
DO j=1-OLy,sNy+OLy |
189 |
|
|
DO i=1-OLx,sNx+OLx |
190 |
mlosch |
1.10 |
zetaPre(I,J,bi,bj) = zeta(I,J,bi,bj) |
191 |
mlosch |
1.28 |
zetaZPre(I,J,bi,bj)= zetaZ(I,J,bi,bj) |
192 |
mlosch |
1.10 |
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 |
mlosch |
1.1 |
ENDDO |
196 |
|
|
ENDDO |
197 |
|
|
ENDDO |
198 |
|
|
ENDDO |
199 |
|
|
C compute convergence criterion for linear preconditioned FGMRES |
200 |
|
|
JFNKgamma_lin = JFNKgamma_lin_max |
201 |
mlosch |
1.18 |
IF ( newtonIter.GT.1.AND.newtonIter.LE.SEAICE_JFNK_tolIter |
202 |
mlosch |
1.1 |
& .AND.JFNKresidual.LT.JFNKres_t ) THEN |
203 |
mlosch |
1.22 |
C Eisenstat and Walker (1996), eq.(2.6) |
204 |
|
|
JFNKgamma_lin = SEAICE_JFNKphi |
205 |
|
|
& *( JFNKresidual/JFNKresidualKm1 )**SEAICE_JFNKalpha |
206 |
mlosch |
1.1 |
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 |
jmc |
1.20 |
|
212 |
mlosch |
1.1 |
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 |
jmc |
1.20 |
|
220 |
mlosch |
1.1 |
JFNKconverged = JFNKresidual.LT.JFNKtol |
221 |
jmc |
1.20 |
|
222 |
mlosch |
1.1 |
C do Krylov loop only if convergence is not reached |
223 |
jmc |
1.20 |
|
224 |
mlosch |
1.1 |
IF ( .NOT.JFNKconverged ) THEN |
225 |
jmc |
1.20 |
|
226 |
mlosch |
1.1 |
C start Krylov iteration (FGMRES) |
227 |
jmc |
1.20 |
|
228 |
mlosch |
1.1 |
krylovConverged = .FALSE. |
229 |
|
|
FGMRESeps = JFNKgamma_lin * JFNKresidual |
230 |
jmc |
1.20 |
DO WHILE ( .NOT.krylovConverged ) |
231 |
mlosch |
1.1 |
C solution vector sol = du/vIce |
232 |
|
|
C residual vector (rhs) Fu = u/vIceRes |
233 |
jmc |
1.20 |
C output work vectors wk1, -> input work vector wk2 |
234 |
|
|
|
235 |
mlosch |
1.1 |
CALL SEAICE_FGMRES_DRIVER( |
236 |
jmc |
1.20 |
I uIceRes, vIceRes, |
237 |
mlosch |
1.1 |
U duIce, dvIce, iCode, |
238 |
mlosch |
1.5 |
I FGMRESeps, iOutFGMRES, |
239 |
mlosch |
1.1 |
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 |
jmc |
1.20 |
C Call preconditioner |
245 |
mlosch |
1.7 |
IF ( SOLV_MAX_ITERS .GT. 0 ) |
246 |
jmc |
1.20 |
& CALL SEAICE_PRECONDITIONER( |
247 |
|
|
U duIce, dvIce, |
248 |
mlosch |
1.28 |
I zetaPre, etaPre, etaZpre, zetaZpre, dwatPre, |
249 |
mlosch |
1.1 |
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 |
jmc |
1.20 |
U duIce, dvIce, |
255 |
mlosch |
1.1 |
I newtonIter, krylovIter, myTime, myIter, myThid ) |
256 |
|
|
ENDIF |
257 |
|
|
krylovConverged = iCode.EQ.0 |
258 |
|
|
C End of Krylov iterate |
259 |
|
|
ENDDO |
260 |
mlosch |
1.5 |
totalKrylovItersLoc = totalKrylovItersLoc + krylovIter |
261 |
mlosch |
1.1 |
C some output diagnostics |
262 |
|
|
IF ( debugLevel.GE.debLevA ) THEN |
263 |
mlosch |
1.5 |
_BEGIN_MASTER( myThid ) |
264 |
jmc |
1.20 |
totalNewtonItersLoc = |
265 |
mlosch |
1.13 |
& SEAICEnewtonIterMax*(myIter-nIter0)+newtonIter |
266 |
jmc |
1.20 |
WRITE(msgBuf,'(2A,2(1XI6),2E12.5)') |
267 |
mlosch |
1.13 |
& ' 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 |
mlosch |
1.1 |
WRITE(msgBuf,'(3(A,I6))') |
274 |
jmc |
1.20 |
& ' S/R SEAICE_JFNK: Newton iterate / total = ',newtonIter, |
275 |
mlosch |
1.13 |
& ' / ', totalNewtonItersLoc, |
276 |
mlosch |
1.1 |
& ', Nb. of FGMRES iterations = ', krylovIter |
277 |
|
|
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
278 |
|
|
& SQUEEZE_RIGHT, myThid ) |
279 |
mlosch |
1.5 |
_END_MASTER( myThid ) |
280 |
mlosch |
1.1 |
ENDIF |
281 |
|
|
IF ( krylovIter.EQ.SEAICEkrylovIterMax ) THEN |
282 |
mlosch |
1.5 |
krylovFails = krylovFails + 1 |
283 |
mlosch |
1.1 |
ENDIF |
284 |
mlosch |
1.17 |
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 |
mlosch |
1.1 |
C Update linear solution vector and return to Newton iteration |
292 |
mlosch |
1.15 |
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 |
jmc |
1.20 |
CALL SEAICE_JFNK_UPDATE( |
298 |
|
|
I duIce, dvIce, |
299 |
mlosch |
1.15 |
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 |
mlosch |
1.1 |
DO bj=myByLo(myThid),myByHi(myThid) |
304 |
|
|
DO bi=myBxLo(myThid),myBxHi(myThid) |
305 |
jmc |
1.20 |
DO J=1-OLy,sNy+OLy |
306 |
|
|
DO I=1-OLx,sNx+OLx |
307 |
mlosch |
1.4 |
duIce(I,J,bi,bj)= 0. _d 0 |
308 |
|
|
dvIce(I,J,bi,bj)= 0. _d 0 |
309 |
mlosch |
1.1 |
ENDDO |
310 |
|
|
ENDDO |
311 |
|
|
ENDDO |
312 |
|
|
ENDDO |
313 |
|
|
ENDIF |
314 |
|
|
C end of Newton iterate |
315 |
|
|
ENDDO |
316 |
jmc |
1.20 |
|
317 |
mlosch |
1.5 |
C-- Output diagnostics |
318 |
jmc |
1.20 |
|
319 |
mlosch |
1.6 |
IF ( SEAICE_monFreq .GT. 0. _d 0 ) THEN |
320 |
mlosch |
1.5 |
C Count iterations |
321 |
mlosch |
1.6 |
totalJFNKtimeSteps = totalJFNKtimeSteps + 1 |
322 |
|
|
totalNewtonIters = totalNewtonIters + newtonIter |
323 |
|
|
totalKrylovIters = totalKrylovIters + totalKrylovItersLoc |
324 |
mlosch |
1.5 |
C Record failure |
325 |
mlosch |
1.6 |
totalKrylovFails = totalKrylovFails + krylovFails |
326 |
|
|
IF ( newtonIter .EQ. SEAICEnewtonIterMax ) THEN |
327 |
jmc |
1.20 |
totalNewtonFails = totalNewtonFails + 1 |
328 |
mlosch |
1.6 |
ENDIF |
329 |
mlosch |
1.5 |
ENDIF |
330 |
|
|
C Decide whether it is time to dump and reset the counter |
331 |
mlosch |
1.9 |
writeNow = DIFFERENT_MULTIPLE(SEAICE_monFreq, |
332 |
jmc |
1.20 |
& myTime+deltaTClock, deltaTClock) |
333 |
mlosch |
1.9 |
#ifdef ALLOW_CAL |
334 |
|
|
IF ( useCAL ) THEN |
335 |
jmc |
1.20 |
CALL CAL_TIME2DUMP( |
336 |
mlosch |
1.9 |
I zeroRL, SEAICE_monFreq, deltaTClock, |
337 |
|
|
U writeNow, |
338 |
|
|
I myTime+deltaTclock, myIter+1, myThid ) |
339 |
|
|
ENDIF |
340 |
|
|
#endif |
341 |
|
|
IF ( writeNow ) THEN |
342 |
mlosch |
1.5 |
_BEGIN_MASTER( myThid ) |
343 |
jmc |
1.20 |
WRITE(msgBuf,'(A)') |
344 |
mlosch |
1.5 |
&' // =======================================================' |
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 |
jmc |
1.20 |
WRITE(msgBuf,'(A)') |
351 |
mlosch |
1.5 |
&' // =======================================================' |
352 |
|
|
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
353 |
|
|
& SQUEEZE_RIGHT, myThid ) |
354 |
jmc |
1.20 |
WRITE(msgBuf,'(A,I10)') |
355 |
mlosch |
1.5 |
& ' %JFNK_MON: time step = ', myIter+1 |
356 |
|
|
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
357 |
|
|
& SQUEEZE_RIGHT, myThid ) |
358 |
jmc |
1.20 |
WRITE(msgBuf,'(A,I10)') |
359 |
mlosch |
1.5 |
& ' %JFNK_MON: Nb. of time steps = ', totalJFNKtimeSteps |
360 |
|
|
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
361 |
|
|
& SQUEEZE_RIGHT, myThid ) |
362 |
jmc |
1.20 |
WRITE(msgBuf,'(A,I10)') |
363 |
mlosch |
1.5 |
& ' %JFNK_MON: Nb. of Newton steps = ', totalNewtonIters |
364 |
|
|
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
365 |
|
|
& SQUEEZE_RIGHT, myThid ) |
366 |
jmc |
1.20 |
WRITE(msgBuf,'(A,I10)') |
367 |
mlosch |
1.5 |
& ' %JFNK_MON: Nb. of Krylov steps = ', totalKrylovIters |
368 |
|
|
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
369 |
|
|
& SQUEEZE_RIGHT, myThid ) |
370 |
jmc |
1.20 |
WRITE(msgBuf,'(A,I10)') |
371 |
mlosch |
1.5 |
& ' %JFNK_MON: Nb. of Newton failures = ', totalNewtonFails |
372 |
|
|
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
373 |
|
|
& SQUEEZE_RIGHT, myThid ) |
374 |
jmc |
1.20 |
WRITE(msgBuf,'(A,I10)') |
375 |
mlosch |
1.5 |
& ' %JFNK_MON: Nb. of Krylov failures = ', totalKrylovFails |
376 |
|
|
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
377 |
|
|
& SQUEEZE_RIGHT, myThid ) |
378 |
jmc |
1.20 |
WRITE(msgBuf,'(A)') |
379 |
mlosch |
1.5 |
&' // =======================================================' |
380 |
|
|
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
381 |
|
|
& SQUEEZE_RIGHT, myThid ) |
382 |
mlosch |
1.11 |
WRITE(msgBuf,'(A)') ' // End JFNK statistics' |
383 |
mlosch |
1.5 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
384 |
|
|
& SQUEEZE_RIGHT, myThid ) |
385 |
jmc |
1.20 |
WRITE(msgBuf,'(A)') |
386 |
mlosch |
1.5 |
&' // =======================================================' |
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 |
mlosch |
1.1 |
IF ( debugLevel.GE.debLevA ) THEN |
400 |
|
|
IF ( newtonIter .EQ. SEAICEnewtonIterMax ) THEN |
401 |
mlosch |
1.5 |
_BEGIN_MASTER( myThid ) |
402 |
jmc |
1.20 |
WRITE(msgBuf,'(A,I10)') |
403 |
mlosch |
1.1 |
& ' S/R SEAICE_JFNK: JFNK did not converge in timestep ', |
404 |
mlosch |
1.5 |
& myIter+1 |
405 |
mlosch |
1.1 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
406 |
|
|
& SQUEEZE_RIGHT, myThid ) |
407 |
mlosch |
1.5 |
_END_MASTER( myThid ) |
408 |
mlosch |
1.1 |
ENDIF |
409 |
mlosch |
1.5 |
IF ( krylovFails .GT. 0 ) THEN |
410 |
|
|
_BEGIN_MASTER( myThid ) |
411 |
jmc |
1.20 |
WRITE(msgBuf,'(A,I4,A,I10)') |
412 |
mlosch |
1.1 |
& ' S/R SEAICE_JFNK: FGMRES did not converge ', |
413 |
mlosch |
1.5 |
& krylovFails, ' times in timestep ', myIter+1 |
414 |
mlosch |
1.1 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
415 |
|
|
& SQUEEZE_RIGHT, myThid ) |
416 |
mlosch |
1.5 |
_END_MASTER( myThid ) |
417 |
mlosch |
1.1 |
ENDIF |
418 |
mlosch |
1.5 |
_BEGIN_MASTER( myThid ) |
419 |
jmc |
1.20 |
WRITE(msgBuf,'(A,I6,A,I10)') |
420 |
mlosch |
1.1 |
& ' S/R SEAICE_JFNK: Total number FGMRES iterations = ', |
421 |
mlosch |
1.5 |
& totalKrylovItersLoc, ' in timestep ', myIter+1 |
422 |
|
|
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
423 |
|
|
& SQUEEZE_RIGHT, myThid ) |
424 |
|
|
_END_MASTER( myThid ) |
425 |
mlosch |
1.1 |
ENDIF |
426 |
|
|
|
427 |
mlosch |
1.15 |
RETURN |
428 |
|
|
END |
429 |
|
|
|
430 |
mlosch |
1.16 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
431 |
mlosch |
1.15 |
CBOP |
432 |
|
|
C !ROUTINE: SEAICE_JFNK_UPDATE |
433 |
|
|
C !INTERFACE: |
434 |
|
|
|
435 |
jmc |
1.20 |
SUBROUTINE SEAICE_JFNK_UPDATE( |
436 |
|
|
I duIce, dvIce, |
437 |
mlosch |
1.15 |
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 |
mlosch |
1.16 |
C !LOCAL VARIABLES: |
488 |
|
|
C === Local variables === |
489 |
mlosch |
1.15 |
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 |
jmc |
1.20 |
C resTmp :: vector version of the residuals |
496 |
mlosch |
1.15 |
INTEGER nVec |
497 |
|
|
PARAMETER ( nVec = 2*sNx*sNy ) |
498 |
|
|
_RL resTmp (nVec,1,nSx,nSy) |
499 |
jmc |
1.20 |
|
500 |
mlosch |
1.15 |
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 |
jmc |
1.20 |
DO J=1-OLy,sNy+OLy |
513 |
|
|
DO I=1-OLx,sNx+OLx |
514 |
mlosch |
1.15 |
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 |
jmc |
1.20 |
CALL SEAICE_CALC_RESIDUAL( |
523 |
|
|
I uIce, vIce, |
524 |
|
|
O uIceRes, vIceRes, |
525 |
mlosch |
1.15 |
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 |
mlosch |
1.19 |
C Determine, if we need more iterations |
532 |
jmc |
1.20 |
doLineSearch = resLoc .GE. JFNKresidual |
533 |
mlosch |
1.19 |
C Limit the maximum number of iterations arbitrarily to four |
534 |
jmc |
1.20 |
doLineSearch = doLineSearch .AND. l .LT. 4 |
535 |
mlosch |
1.19 |
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 |
mlosch |
1.15 |
C some output diagnostics |
544 |
|
|
IF ( debugLevel.GE.debLevA .AND. doLineSearch ) THEN |
545 |
|
|
_BEGIN_MASTER( myThid ) |
546 |
jmc |
1.20 |
WRITE(msgBuf,'(2A,2(1XI6),3E12.5)') |
547 |
mlosch |
1.15 |
& ' 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 |
mlosch |
1.21 |
#endif /* SEAICE_ALLOW_JFNK */ |
563 |
mlosch |
1.1 |
|
564 |
|
|
RETURN |
565 |
|
|
END |