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