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