2 |
C $Name$ |
C $Name$ |
3 |
|
|
4 |
#include "SEAICE_OPTIONS.h" |
#include "SEAICE_OPTIONS.h" |
5 |
|
#ifdef ALLOW_AUTODIFF |
6 |
|
# include "AUTODIFF_OPTIONS.h" |
7 |
|
#endif |
8 |
|
|
9 |
C-- File seaice_jfnk.F: seaice jfnk dynamical solver S/R: |
C-- File seaice_jfnk.F: seaice jfnk dynamical solver S/R: |
10 |
C-- Contents |
C-- Contents |
56 |
INTEGER myIter |
INTEGER myIter |
57 |
INTEGER myThid |
INTEGER myThid |
58 |
|
|
59 |
#if ( (defined SEAICE_CGRID) && \ |
#ifdef SEAICE_ALLOW_JFNK |
|
(defined SEAICE_ALLOW_JFNK) && \ |
|
|
(defined SEAICE_ALLOW_DYNAMICS) ) |
|
60 |
C !FUNCTIONS: |
C !FUNCTIONS: |
61 |
LOGICAL DIFFERENT_MULTIPLE |
LOGICAL DIFFERENT_MULTIPLE |
62 |
EXTERNAL DIFFERENT_MULTIPLE |
EXTERNAL DIFFERENT_MULTIPLE |
76 |
_RL JFNKresidual |
_RL JFNKresidual |
77 |
_RL JFNKresidualKm1 |
_RL JFNKresidualKm1 |
78 |
C parameters to compute convergence criterion |
C parameters to compute convergence criterion |
79 |
_RL phi_e, alp_e, JFNKgamma_lin |
_RL JFNKgamma_lin |
80 |
_RL FGMRESeps |
_RL FGMRESeps |
81 |
_RL JFNKtol |
_RL JFNKtol |
82 |
C |
C backward differences extrapolation factors |
83 |
|
_RL bdfFac, bdfAlpha |
84 |
|
C |
85 |
_RL recip_deltaT |
_RL recip_deltaT |
86 |
LOGICAL JFNKconverged, krylovConverged |
LOGICAL JFNKconverged, krylovConverged |
87 |
LOGICAL writeNow |
LOGICAL writeNow |
88 |
CHARACTER*(MAX_LEN_MBUF) msgBuf |
CHARACTER*(MAX_LEN_MBUF) msgBuf |
89 |
C |
|
90 |
C u/vIceRes :: residual of sea-ice momentum equations |
C u/vIceRes :: residual of sea-ice momentum equations |
91 |
_RL uIceRes(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy) |
_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) |
_RL vIceRes(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy) |
93 |
C vector version of the residuals |
C extra time level required for backward difference time stepping |
94 |
_RL resTmp (nVec,1,nSx,nSy) |
_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 |
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) |
_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) |
_RL dvIce (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy) |
99 |
C precomputed (= constant per Newton iteration) versions of |
C precomputed (= constant per Newton iteration) versions of |
100 |
C zeta, eta, and DWATN, press |
C zeta, eta, and DWATN, press |
101 |
_RL zetaPre (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy) |
_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) |
_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) |
_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) |
_RL dwatPre (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy) |
122 |
& DIFFERENT_MULTIPLE( SEAICE_monFreq, myTime, deltaTClock ) ) |
& DIFFERENT_MULTIPLE( SEAICE_monFreq, myTime, deltaTClock ) ) |
123 |
& iOutFGMRES=1 |
& iOutFGMRES=1 |
124 |
|
|
125 |
C |
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) |
DO bj=myByLo(myThid),myByHi(myThid) |
137 |
DO bi=myBxLo(myThid),myBxHi(myThid) |
DO bi=myBxLo(myThid),myBxHi(myThid) |
138 |
DO J=1-Oly,sNy+Oly |
DO J=1-OLy,sNy+OLy |
139 |
DO I=1-Olx,sNx+Olx |
DO I=1-OLx,sNx+OLx |
140 |
uIceRes(I,J,bi,bj) = 0. _d 0 |
uIceRes(I,J,bi,bj) = 0. _d 0 |
141 |
vIceRes(I,J,bi,bj) = 0. _d 0 |
vIceRes(I,J,bi,bj) = 0. _d 0 |
142 |
duIce (I,J,bi,bj) = 0. _d 0 |
duIce (I,J,bi,bj) = 0. _d 0 |
143 |
dvIce (I,J,bi,bj) = 0. _d 0 |
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) |
uIceNm1(I,J,bi,bj) = uIce(I,J,bi,bj) |
154 |
vIceNm1(I,J,bi,bj) = vIce(I,J,bi,bj) |
vIceNm1(I,J,bi,bj) = vIce(I,J,bi,bj) |
155 |
ENDDO |
ENDDO |
156 |
ENDDO |
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: |
C Compute things that do no change during the Newton iteration: |
160 |
C sea-surface tilt and wind stress: |
C sea-surface tilt and wind stress: |
161 |
C FORCEX/Y0 - mass*(u/vIceNm1)/deltaT |
C FORCEX/Y0 - mass*(1.5*u/vIceNm1+0.5*(u/vIceNm1-u/vIceNm2))/deltaT |
162 |
DO J=1-Oly,sNy+Oly |
DO J=1-OLy,sNy+OLy |
163 |
DO I=1-Olx,sNx+Olx |
DO I=1-OLx,sNx+OLx |
164 |
FORCEX(I,J,bi,bj) = FORCEX0(I,J,bi,bj) |
FORCEX(I,J,bi,bj) = FORCEX0(I,J,bi,bj) |
165 |
& + seaiceMassU(I,J,bi,bj)*uIceNm1(I,J,bi,bj)*recip_deltaT |
& + seaiceMassU(I,J,bi,bj)*duIcNm1(I,J,bi,bj)*recip_deltaT |
166 |
FORCEY(I,J,bi,bj) = FORCEY0(I,J,bi,bj) |
FORCEY(I,J,bi,bj) = FORCEY0(I,J,bi,bj) |
167 |
& + seaiceMassV(I,J,bi,bj)*vIceNm1(I,J,bi,bj)*recip_deltaT |
& + seaiceMassV(I,J,bi,bj)*dvIcNm1(I,J,bi,bj)*recip_deltaT |
168 |
ENDDO |
ENDDO |
169 |
ENDDO |
ENDDO |
170 |
|
CML ENDIF |
171 |
ENDDO |
ENDDO |
172 |
ENDDO |
ENDDO |
173 |
C Start nonlinear Newton iteration: outer loop iteration |
C Start nonlinear Newton iteration: outer loop iteration |
176 |
newtonIter = newtonIter + 1 |
newtonIter = newtonIter + 1 |
177 |
C Compute initial residual F(u), (includes computation of global |
C Compute initial residual F(u), (includes computation of global |
178 |
C variables DWATN, zeta, and eta) |
C variables DWATN, zeta, and eta) |
179 |
IF ( newtonIter .EQ. 1 ) CALL SEAICE_JFNK_UPDATE( |
IF ( newtonIter .EQ. 1 ) CALL SEAICE_JFNK_UPDATE( |
180 |
I duIce, dvIce, |
I duIce, dvIce, |
181 |
U uIce, vIce, JFNKresidual, |
U uIce, vIce, JFNKresidual, |
182 |
O uIceRes, vIceRes, |
O uIceRes, vIceRes, |
183 |
I newtonIter, myTime, myIter, myThid ) |
I newtonIter, myTime, myIter, myThid ) |
185 |
C constant for the preconditioner |
C constant for the preconditioner |
186 |
DO bj=myByLo(myThid),myByHi(myThid) |
DO bj=myByLo(myThid),myByHi(myThid) |
187 |
DO bi=myBxLo(myThid),myBxHi(myThid) |
DO bi=myBxLo(myThid),myBxHi(myThid) |
188 |
DO j=1-Oly,sNy+Oly |
DO j=1-OLy,sNy+OLy |
189 |
DO i=1-Olx,sNx+Olx |
DO i=1-OLx,sNx+OLx |
190 |
zetaPre(I,J,bi,bj) = zeta(I,J,bi,bj) |
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) |
etaPre(I,J,bi,bj) = eta(I,J,bi,bj) |
193 |
etaZPre(I,J,bi,bj) = etaZ(I,J,bi,bj) |
etaZPre(I,J,bi,bj) = etaZ(I,J,bi,bj) |
194 |
dwatPre(I,J,bi,bj) = DWATN(I,J,bi,bj) |
dwatPre(I,J,bi,bj) = DWATN(I,J,bi,bj) |
198 |
ENDDO |
ENDDO |
199 |
C compute convergence criterion for linear preconditioned FGMRES |
C compute convergence criterion for linear preconditioned FGMRES |
200 |
JFNKgamma_lin = JFNKgamma_lin_max |
JFNKgamma_lin = JFNKgamma_lin_max |
201 |
IF ( newtonIter.GT.1.AND.newtonIter.LE.100 |
IF ( newtonIter.GT.1.AND.newtonIter.LE.SEAICE_JFNK_tolIter |
202 |
& .AND.JFNKresidual.LT.JFNKres_t ) THEN |
& .AND.JFNKresidual.LT.JFNKres_t ) THEN |
203 |
C Eisenstat, 1996, equ.(2.6) |
C Eisenstat and Walker (1996), eq.(2.6) |
204 |
phi_e = 1. _d 0 |
JFNKgamma_lin = SEAICE_JFNKphi |
205 |
alp_e = 1. _d 0 |
& *( JFNKresidual/JFNKresidualKm1 )**SEAICE_JFNKalpha |
|
JFNKgamma_lin = phi_e*( JFNKresidual/JFNKresidualKm1 )**alp_e |
|
206 |
JFNKgamma_lin = min(JFNKgamma_lin_max, JFNKgamma_lin) |
JFNKgamma_lin = min(JFNKgamma_lin_max, JFNKgamma_lin) |
207 |
JFNKgamma_lin = max(JFNKgamma_lin_min, JFNKgamma_lin) |
JFNKgamma_lin = max(JFNKgamma_lin_min, JFNKgamma_lin) |
208 |
ENDIF |
ENDIF |
209 |
C save the residual for the next iteration |
C save the residual for the next iteration |
210 |
JFNKresidualKm1 = JFNKresidual |
JFNKresidualKm1 = JFNKresidual |
211 |
C |
|
212 |
C The Krylov iteration using FGMRES, the preconditioner is LSOR |
C The Krylov iteration using FGMRES, the preconditioner is LSOR |
213 |
C for now. The code is adapted from SEAICE_LSR, but heavily stripped |
C for now. The code is adapted from SEAICE_LSR, but heavily stripped |
214 |
C down. |
C down. |
216 |
C in that routine |
C in that routine |
217 |
krylovIter = 0 |
krylovIter = 0 |
218 |
iCode = 0 |
iCode = 0 |
219 |
C |
|
220 |
JFNKconverged = JFNKresidual.LT.JFNKtol |
JFNKconverged = JFNKresidual.LT.JFNKtol |
221 |
C |
|
222 |
C do Krylov loop only if convergence is not reached |
C do Krylov loop only if convergence is not reached |
223 |
C |
|
224 |
IF ( .NOT.JFNKconverged ) THEN |
IF ( .NOT.JFNKconverged ) THEN |
225 |
C |
|
226 |
C start Krylov iteration (FGMRES) |
C start Krylov iteration (FGMRES) |
227 |
C |
|
228 |
krylovConverged = .FALSE. |
krylovConverged = .FALSE. |
229 |
FGMRESeps = JFNKgamma_lin * JFNKresidual |
FGMRESeps = JFNKgamma_lin * JFNKresidual |
230 |
DO WHILE ( .NOT.krylovConverged ) |
DO WHILE ( .NOT.krylovConverged ) |
231 |
C solution vector sol = du/vIce |
C solution vector sol = du/vIce |
232 |
C residual vector (rhs) Fu = u/vIceRes |
C residual vector (rhs) Fu = u/vIceRes |
233 |
C output work vectors wk1, -> input work vector wk2 |
C output work vectors wk1, -> input work vector wk2 |
234 |
C |
|
235 |
CALL SEAICE_FGMRES_DRIVER( |
CALL SEAICE_FGMRES_DRIVER( |
236 |
I uIceRes, vIceRes, |
I uIceRes, vIceRes, |
237 |
U duIce, dvIce, iCode, |
U duIce, dvIce, iCode, |
238 |
I FGMRESeps, iOutFGMRES, |
I FGMRESeps, iOutFGMRES, |
239 |
I newtonIter, krylovIter, myTime, myIter, myThid ) |
I newtonIter, krylovIter, myTime, myIter, myThid ) |
241 |
C or product of matrix (Jacobian) times vector. For iCode = 0, terminate |
C or product of matrix (Jacobian) times vector. For iCode = 0, terminate |
242 |
C iteration |
C iteration |
243 |
IF (iCode.EQ.1) THEN |
IF (iCode.EQ.1) THEN |
244 |
C Call preconditioner |
C Call preconditioner |
245 |
IF ( SOLV_MAX_ITERS .GT. 0 ) |
IF ( SOLV_MAX_ITERS .GT. 0 ) |
246 |
& CALL SEAICE_PRECONDITIONER( |
& CALL SEAICE_PRECONDITIONER( |
247 |
U duIce, dvIce, |
U duIce, dvIce, |
248 |
I zetaPre, etaPre, etaZpre, dwatPre, |
I zetaPre, etaPre, etaZpre, zetaZpre, dwatPre, |
249 |
I newtonIter, krylovIter, myTime, myIter, myThid ) |
I newtonIter, krylovIter, myTime, myIter, myThid ) |
250 |
ELSEIF (iCode.GE.2) THEN |
ELSEIF (iCode.GE.2) THEN |
251 |
C Compute Jacobian times vector |
C Compute Jacobian times vector |
252 |
CALL SEAICE_JACVEC( |
CALL SEAICE_JACVEC( |
253 |
I uIce, vIce, uIceRes, vIceRes, |
I uIce, vIce, uIceRes, vIceRes, |
254 |
U duIce, dvIce, |
U duIce, dvIce, |
255 |
I newtonIter, krylovIter, myTime, myIter, myThid ) |
I newtonIter, krylovIter, myTime, myIter, myThid ) |
256 |
ENDIF |
ENDIF |
257 |
krylovConverged = iCode.EQ.0 |
krylovConverged = iCode.EQ.0 |
261 |
C some output diagnostics |
C some output diagnostics |
262 |
IF ( debugLevel.GE.debLevA ) THEN |
IF ( debugLevel.GE.debLevA ) THEN |
263 |
_BEGIN_MASTER( myThid ) |
_BEGIN_MASTER( myThid ) |
264 |
totalNewtonItersLoc = |
totalNewtonItersLoc = |
265 |
& SEAICEnewtonIterMax*(myIter-nIter0)+newtonIter |
& SEAICEnewtonIterMax*(myIter-nIter0)+newtonIter |
266 |
WRITE(msgBuf,'(2A,2(1XI6),2E12.5)') |
WRITE(msgBuf,'(2A,2(1XI6),2E12.5)') |
267 |
& ' S/R SEAICE_JFNK: Newton iterate / total, ', |
& ' S/R SEAICE_JFNK: Newton iterate / total, ', |
268 |
& 'JFNKgamma_lin, initial norm = ', |
& 'JFNKgamma_lin, initial norm = ', |
269 |
& newtonIter, totalNewtonItersLoc, |
& newtonIter, totalNewtonItersLoc, |
271 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
272 |
& SQUEEZE_RIGHT, myThid ) |
& SQUEEZE_RIGHT, myThid ) |
273 |
WRITE(msgBuf,'(3(A,I6))') |
WRITE(msgBuf,'(3(A,I6))') |
274 |
& ' S/R SEAICE_JFNK: Newton iterate / total = ',newtonIter, |
& ' S/R SEAICE_JFNK: Newton iterate / total = ',newtonIter, |
275 |
& ' / ', totalNewtonItersLoc, |
& ' / ', totalNewtonItersLoc, |
276 |
& ', Nb. of FGMRES iterations = ', krylovIter |
& ', Nb. of FGMRES iterations = ', krylovIter |
277 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
281 |
IF ( krylovIter.EQ.SEAICEkrylovIterMax ) THEN |
IF ( krylovIter.EQ.SEAICEkrylovIterMax ) THEN |
282 |
krylovFails = krylovFails + 1 |
krylovFails = krylovFails + 1 |
283 |
ENDIF |
ENDIF |
284 |
C Set the stopping criterion for the Newton iteration |
C Set the stopping criterion for the Newton iteration and the |
285 |
IF ( newtonIter .EQ. 1 ) JFNKtol=JFNKgamma_nonlin*JFNKresidual |
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 |
C Update linear solution vector and return to Newton iteration |
292 |
C Do a linesearch if necessary, and compute a new residual. |
C Do a linesearch if necessary, and compute a new residual. |
293 |
C Note that it should be possible to do the following operations |
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 |
C at the beginning of the Newton iteration, thereby saving us from |
295 |
C the extra call of seaice_jfnk_update, but unfortunately that |
C the extra call of seaice_jfnk_update, but unfortunately that |
296 |
C changes the results, so we leave the stuff here for now. |
C changes the results, so we leave the stuff here for now. |
297 |
CALL SEAICE_JFNK_UPDATE( |
CALL SEAICE_JFNK_UPDATE( |
298 |
I duIce, dvIce, |
I duIce, dvIce, |
299 |
U uIce, vIce, JFNKresidual, |
U uIce, vIce, JFNKresidual, |
300 |
O uIceRes, vIceRes, |
O uIceRes, vIceRes, |
301 |
I newtonIter, myTime, myIter, myThid ) |
I newtonIter, myTime, myIter, myThid ) |
302 |
C reset du/vIce here instead of setting sol = 0 in seaice_fgmres_driver |
C reset du/vIce here instead of setting sol = 0 in seaice_fgmres_driver |
303 |
DO bj=myByLo(myThid),myByHi(myThid) |
DO bj=myByLo(myThid),myByHi(myThid) |
304 |
DO bi=myBxLo(myThid),myBxHi(myThid) |
DO bi=myBxLo(myThid),myBxHi(myThid) |
305 |
DO J=1-Oly,sNy+Oly |
DO J=1-OLy,sNy+OLy |
306 |
DO I=1-Olx,sNx+Olx |
DO I=1-OLx,sNx+OLx |
307 |
duIce(I,J,bi,bj)= 0. _d 0 |
duIce(I,J,bi,bj)= 0. _d 0 |
308 |
dvIce(I,J,bi,bj)= 0. _d 0 |
dvIce(I,J,bi,bj)= 0. _d 0 |
309 |
ENDDO |
ENDDO |
313 |
ENDIF |
ENDIF |
314 |
C end of Newton iterate |
C end of Newton iterate |
315 |
ENDDO |
ENDDO |
316 |
C |
|
317 |
C-- Output diagnostics |
C-- Output diagnostics |
318 |
C |
|
319 |
IF ( SEAICE_monFreq .GT. 0. _d 0 ) THEN |
IF ( SEAICE_monFreq .GT. 0. _d 0 ) THEN |
320 |
C Count iterations |
C Count iterations |
321 |
totalJFNKtimeSteps = totalJFNKtimeSteps + 1 |
totalJFNKtimeSteps = totalJFNKtimeSteps + 1 |
324 |
C Record failure |
C Record failure |
325 |
totalKrylovFails = totalKrylovFails + krylovFails |
totalKrylovFails = totalKrylovFails + krylovFails |
326 |
IF ( newtonIter .EQ. SEAICEnewtonIterMax ) THEN |
IF ( newtonIter .EQ. SEAICEnewtonIterMax ) THEN |
327 |
totalNewtonFails = totalNewtonFails + 1 |
totalNewtonFails = totalNewtonFails + 1 |
328 |
ENDIF |
ENDIF |
329 |
ENDIF |
ENDIF |
330 |
C Decide whether it is time to dump and reset the counter |
C Decide whether it is time to dump and reset the counter |
331 |
writeNow = DIFFERENT_MULTIPLE(SEAICE_monFreq, |
writeNow = DIFFERENT_MULTIPLE(SEAICE_monFreq, |
332 |
& myTime+deltaTClock, deltaTClock) |
& myTime+deltaTClock, deltaTClock) |
333 |
#ifdef ALLOW_CAL |
#ifdef ALLOW_CAL |
334 |
IF ( useCAL ) THEN |
IF ( useCAL ) THEN |
335 |
CALL CAL_TIME2DUMP( |
CALL CAL_TIME2DUMP( |
336 |
I zeroRL, SEAICE_monFreq, deltaTClock, |
I zeroRL, SEAICE_monFreq, deltaTClock, |
337 |
U writeNow, |
U writeNow, |
338 |
I myTime+deltaTclock, myIter+1, myThid ) |
I myTime+deltaTclock, myIter+1, myThid ) |
340 |
#endif |
#endif |
341 |
IF ( writeNow ) THEN |
IF ( writeNow ) THEN |
342 |
_BEGIN_MASTER( myThid ) |
_BEGIN_MASTER( myThid ) |
343 |
WRITE(msgBuf,'(A)') |
WRITE(msgBuf,'(A)') |
344 |
&' // =======================================================' |
&' // =======================================================' |
345 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
346 |
& SQUEEZE_RIGHT, myThid ) |
& SQUEEZE_RIGHT, myThid ) |
347 |
WRITE(msgBuf,'(A)') ' // Begin JFNK statistics' |
WRITE(msgBuf,'(A)') ' // Begin JFNK statistics' |
348 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
349 |
& SQUEEZE_RIGHT, myThid ) |
& SQUEEZE_RIGHT, myThid ) |
350 |
WRITE(msgBuf,'(A)') |
WRITE(msgBuf,'(A)') |
351 |
&' // =======================================================' |
&' // =======================================================' |
352 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
353 |
& SQUEEZE_RIGHT, myThid ) |
& SQUEEZE_RIGHT, myThid ) |
354 |
WRITE(msgBuf,'(A,I10)') |
WRITE(msgBuf,'(A,I10)') |
355 |
& ' %JFNK_MON: time step = ', myIter+1 |
& ' %JFNK_MON: time step = ', myIter+1 |
356 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
357 |
& SQUEEZE_RIGHT, myThid ) |
& SQUEEZE_RIGHT, myThid ) |
358 |
WRITE(msgBuf,'(A,I10)') |
WRITE(msgBuf,'(A,I10)') |
359 |
& ' %JFNK_MON: Nb. of time steps = ', totalJFNKtimeSteps |
& ' %JFNK_MON: Nb. of time steps = ', totalJFNKtimeSteps |
360 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
361 |
& SQUEEZE_RIGHT, myThid ) |
& SQUEEZE_RIGHT, myThid ) |
362 |
WRITE(msgBuf,'(A,I10)') |
WRITE(msgBuf,'(A,I10)') |
363 |
& ' %JFNK_MON: Nb. of Newton steps = ', totalNewtonIters |
& ' %JFNK_MON: Nb. of Newton steps = ', totalNewtonIters |
364 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
365 |
& SQUEEZE_RIGHT, myThid ) |
& SQUEEZE_RIGHT, myThid ) |
366 |
WRITE(msgBuf,'(A,I10)') |
WRITE(msgBuf,'(A,I10)') |
367 |
& ' %JFNK_MON: Nb. of Krylov steps = ', totalKrylovIters |
& ' %JFNK_MON: Nb. of Krylov steps = ', totalKrylovIters |
368 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
369 |
& SQUEEZE_RIGHT, myThid ) |
& SQUEEZE_RIGHT, myThid ) |
370 |
WRITE(msgBuf,'(A,I10)') |
WRITE(msgBuf,'(A,I10)') |
371 |
& ' %JFNK_MON: Nb. of Newton failures = ', totalNewtonFails |
& ' %JFNK_MON: Nb. of Newton failures = ', totalNewtonFails |
372 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
373 |
& SQUEEZE_RIGHT, myThid ) |
& SQUEEZE_RIGHT, myThid ) |
374 |
WRITE(msgBuf,'(A,I10)') |
WRITE(msgBuf,'(A,I10)') |
375 |
& ' %JFNK_MON: Nb. of Krylov failures = ', totalKrylovFails |
& ' %JFNK_MON: Nb. of Krylov failures = ', totalKrylovFails |
376 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
377 |
& SQUEEZE_RIGHT, myThid ) |
& SQUEEZE_RIGHT, myThid ) |
378 |
WRITE(msgBuf,'(A)') |
WRITE(msgBuf,'(A)') |
379 |
&' // =======================================================' |
&' // =======================================================' |
380 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
381 |
& SQUEEZE_RIGHT, myThid ) |
& SQUEEZE_RIGHT, myThid ) |
382 |
WRITE(msgBuf,'(A)') ' // End JFNK statistics' |
WRITE(msgBuf,'(A)') ' // End JFNK statistics' |
383 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
384 |
& SQUEEZE_RIGHT, myThid ) |
& SQUEEZE_RIGHT, myThid ) |
385 |
WRITE(msgBuf,'(A)') |
WRITE(msgBuf,'(A)') |
386 |
&' // =======================================================' |
&' // =======================================================' |
387 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
388 |
& SQUEEZE_RIGHT, myThid ) |
& SQUEEZE_RIGHT, myThid ) |
399 |
IF ( debugLevel.GE.debLevA ) THEN |
IF ( debugLevel.GE.debLevA ) THEN |
400 |
IF ( newtonIter .EQ. SEAICEnewtonIterMax ) THEN |
IF ( newtonIter .EQ. SEAICEnewtonIterMax ) THEN |
401 |
_BEGIN_MASTER( myThid ) |
_BEGIN_MASTER( myThid ) |
402 |
WRITE(msgBuf,'(A,I10)') |
WRITE(msgBuf,'(A,I10)') |
403 |
& ' S/R SEAICE_JFNK: JFNK did not converge in timestep ', |
& ' S/R SEAICE_JFNK: JFNK did not converge in timestep ', |
404 |
& myIter+1 |
& myIter+1 |
405 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
408 |
ENDIF |
ENDIF |
409 |
IF ( krylovFails .GT. 0 ) THEN |
IF ( krylovFails .GT. 0 ) THEN |
410 |
_BEGIN_MASTER( myThid ) |
_BEGIN_MASTER( myThid ) |
411 |
WRITE(msgBuf,'(A,I4,A,I10)') |
WRITE(msgBuf,'(A,I4,A,I10)') |
412 |
& ' S/R SEAICE_JFNK: FGMRES did not converge ', |
& ' S/R SEAICE_JFNK: FGMRES did not converge ', |
413 |
& krylovFails, ' times in timestep ', myIter+1 |
& krylovFails, ' times in timestep ', myIter+1 |
414 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
416 |
_END_MASTER( myThid ) |
_END_MASTER( myThid ) |
417 |
ENDIF |
ENDIF |
418 |
_BEGIN_MASTER( myThid ) |
_BEGIN_MASTER( myThid ) |
419 |
WRITE(msgBuf,'(A,I6,A,I10)') |
WRITE(msgBuf,'(A,I6,A,I10)') |
420 |
& ' S/R SEAICE_JFNK: Total number FGMRES iterations = ', |
& ' S/R SEAICE_JFNK: Total number FGMRES iterations = ', |
421 |
& totalKrylovItersLoc, ' in timestep ', myIter+1 |
& totalKrylovItersLoc, ' in timestep ', myIter+1 |
422 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
432 |
C !ROUTINE: SEAICE_JFNK_UPDATE |
C !ROUTINE: SEAICE_JFNK_UPDATE |
433 |
C !INTERFACE: |
C !INTERFACE: |
434 |
|
|
435 |
SUBROUTINE SEAICE_JFNK_UPDATE( |
SUBROUTINE SEAICE_JFNK_UPDATE( |
436 |
I duIce, dvIce, |
I duIce, dvIce, |
437 |
U uIce, vIce, JFNKresidual, |
U uIce, vIce, JFNKresidual, |
438 |
O uIceRes, vIceRes, |
O uIceRes, vIceRes, |
439 |
I newtonIter, myTime, myIter, myThid ) |
I newtonIter, myTime, myIter, myThid ) |
492 |
_RL resLoc, facLS |
_RL resLoc, facLS |
493 |
LOGICAL doLineSearch |
LOGICAL doLineSearch |
494 |
C nVec :: size of the input vector(s) |
C nVec :: size of the input vector(s) |
495 |
C vector version of the residuals |
C resTmp :: vector version of the residuals |
496 |
INTEGER nVec |
INTEGER nVec |
497 |
PARAMETER ( nVec = 2*sNx*sNy ) |
PARAMETER ( nVec = 2*sNx*sNy ) |
498 |
_RL resTmp (nVec,1,nSx,nSy) |
_RL resTmp (nVec,1,nSx,nSy) |
499 |
C |
|
500 |
CHARACTER*(MAX_LEN_MBUF) msgBuf |
CHARACTER*(MAX_LEN_MBUF) msgBuf |
501 |
CEOP |
CEOP |
502 |
|
|
506 |
facLS = 1. _d 0 |
facLS = 1. _d 0 |
507 |
doLineSearch = .TRUE. |
doLineSearch = .TRUE. |
508 |
DO WHILE ( doLineSearch ) |
DO WHILE ( doLineSearch ) |
|
C Determine, if we need more iterations |
|
|
doLineSearch = resLoc .GE. JFNKresidual |
|
|
C Limit the maximum number of iterations arbitrarily to four |
|
|
doLineSearch = doLineSearch .AND. l .LE. 4 |
|
|
C For the first iteration du/vIce = 0 and there will be no |
|
|
C improvement of the residual possible, so we do only the first |
|
|
C iteration |
|
|
IF ( newtonIter .EQ. 1 ) doLineSearch = .FALSE. |
|
|
C Only start a linesearch after some Newton iterations |
|
|
IF ( newtonIter .LE. SEAICE_JFNK_lsIter ) doLineSearch = .FALSE. |
|
|
C Increment counter |
|
|
l = l + 1 |
|
509 |
C Create update |
C Create update |
510 |
DO bj=myByLo(myThid),myByHi(myThid) |
DO bj=myByLo(myThid),myByHi(myThid) |
511 |
DO bi=myBxLo(myThid),myBxHi(myThid) |
DO bi=myBxLo(myThid),myBxHi(myThid) |
512 |
DO J=1-Oly,sNy+Oly |
DO J=1-OLy,sNy+OLy |
513 |
DO I=1-Olx,sNx+Olx |
DO I=1-OLx,sNx+OLx |
514 |
uIce(I,J,bi,bj) = uIce(I,J,bi,bj)+facLS*duIce(I,J,bi,bj) |
uIce(I,J,bi,bj) = uIce(I,J,bi,bj)+facLS*duIce(I,J,bi,bj) |
515 |
vIce(I,J,bi,bj) = vIce(I,J,bi,bj)+facLS*dvIce(I,J,bi,bj) |
vIce(I,J,bi,bj) = vIce(I,J,bi,bj)+facLS*dvIce(I,J,bi,bj) |
516 |
ENDDO |
ENDDO |
519 |
ENDDO |
ENDDO |
520 |
C Compute current residual F(u), (includes re-computation of global |
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) |
C variables DWATN, zeta, and eta, i.e. they are different after this) |
522 |
CALL SEAICE_CALC_RESIDUAL( |
CALL SEAICE_CALC_RESIDUAL( |
523 |
I uIce, vIce, |
I uIce, vIce, |
524 |
O uIceRes, vIceRes, |
O uIceRes, vIceRes, |
525 |
I newtonIter, 0, myTime, myIter, myThid ) |
I newtonIter, 0, myTime, myIter, myThid ) |
526 |
C Important: Compute the norm of the residual using the same scalar |
C Important: Compute the norm of the residual using the same scalar |
527 |
C product that SEAICE_FGMRES does |
C product that SEAICE_FGMRES does |
528 |
CALL SEAICE_MAP2VEC(nVec,uIceRes,vIceRes,resTmp,.TRUE.,myThid) |
CALL SEAICE_MAP2VEC(nVec,uIceRes,vIceRes,resTmp,.TRUE.,myThid) |
529 |
CALL SEAICE_SCALPROD(nVec,1,1,1,resTmp,resTmp,resLoc,myThid) |
CALL SEAICE_SCALPROD(nVec,1,1,1,resTmp,resTmp,resLoc,myThid) |
530 |
resLoc = SQRT(resLoc) |
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 |
C some output diagnostics |
544 |
IF ( debugLevel.GE.debLevA .AND. doLineSearch ) THEN |
IF ( debugLevel.GE.debLevA .AND. doLineSearch ) THEN |
545 |
_BEGIN_MASTER( myThid ) |
_BEGIN_MASTER( myThid ) |
546 |
WRITE(msgBuf,'(2A,2(1XI6),3E12.5)') |
WRITE(msgBuf,'(2A,2(1XI6),3E12.5)') |
547 |
& ' S/R SEAICE_JFNK_UPDATE: Newton iter, LSiter, ', |
& ' S/R SEAICE_JFNK_UPDATE: Newton iter, LSiter, ', |
548 |
& 'facLS, JFNKresidual, resLoc = ', |
& 'facLS, JFNKresidual, resLoc = ', |
549 |
& newtonIter, l, facLS, JFNKresidual, resLoc |
& newtonIter, l, facLS, JFNKresidual, resLoc |
559 |
C This is the new residual |
C This is the new residual |
560 |
JFNKresidual = resLoc |
JFNKresidual = resLoc |
561 |
|
|
562 |
#endif /* SEAICE_ALLOW_DYNAMICS and SEAICE_CGRID and SEAICE_ALLOW_JFNK */ |
#endif /* SEAICE_ALLOW_JFNK */ |
563 |
|
|
564 |
RETURN |
RETURN |
565 |
END |
END |