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