--- MITgcm/pkg/seaice/seaice_jfnk.F 2012/11/07 09:56:23 1.5 +++ MITgcm/pkg/seaice/seaice_jfnk.F 2012/12/17 15:06:02 1.13 @@ -1,4 +1,4 @@ -C $Header: /home/ubuntu/mnt/e9_copy/MITgcm/pkg/seaice/seaice_jfnk.F,v 1.5 2012/11/07 09:56:23 mlosch Exp $ +C $Header: /home/ubuntu/mnt/e9_copy/MITgcm/pkg/seaice/seaice_jfnk.F,v 1.13 2012/12/17 15:06:02 mlosch Exp $ C $Name: $ #include "SEAICE_OPTIONS.h" @@ -60,12 +60,12 @@ C loop indices INTEGER newtonIter INTEGER krylovIter, krylovFails - INTEGER totalKrylovItersLoc + INTEGER totalKrylovItersLoc, totalNewtonItersLoc C FGMRES flag that determines amount of output messages of fgmres INTEGER iOutFGMRES C FGMRES flag that indicates what fgmres wants us to do next INTEGER iCode - _RL JFNKresidual, JFNKresidualTile(nSx,nSy) + _RL JFNKresidual _RL JFNKresidualKm1 C parameters to compute convergence criterion _RL phi_e, alp_e, JFNKgamma_lin @@ -74,6 +74,7 @@ C _RL recip_deltaT LOGICAL JFNKconverged, krylovConverged + LOGICAL writeNow CHARACTER*(MAX_LEN_MBUF) msgBuf C C u/vIceRes :: residual of sea-ice momentum equations @@ -86,9 +87,11 @@ C zeta, eta, and DWATN, press _RL zetaPre (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy) _RL etaPre (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy) + _RL etaZPre (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy) _RL dwatPre (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy) - _RL pressPre(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy) CEOP + INTEGER n + _RL resTmp (nVec,1,nSx,nSy) C Initialise newtonIter = 0 @@ -102,8 +105,8 @@ recip_deltaT = 1. _d 0 / SEAICE_deltaTdyn iOutFGMRES=0 -C iOutFgmres=1 gives a little bit of output - IF ( debugLevel.GE.debLevA .AND. +C with iOutFgmres=1, seaice_fgmres prints the residual at each iteration + IF ( debugLevel.GE.debLevC .AND. & DIFFERENT_MULTIPLE( SEAICE_monFreq, myTime, deltaTClock ) ) & iOutFGMRES=1 @@ -143,6 +146,7 @@ I uIce, vIce, O uIceRes, vIceRes, I newtonIter, 0, myTime, myIter, myThid ) +C probably not necessary, will be removed later: CALL EXCH_UV_XY_RL( uIceRes, vIceRes,.TRUE.,myThid) C local copies of precomputed coefficients that are to stay C constant for the preconditioner @@ -150,38 +154,19 @@ DO bi=myBxLo(myThid),myBxHi(myThid) DO j=1-Oly,sNy+Oly DO i=1-Olx,sNx+Olx - zetaPre(I,J,bi,bj) = zeta(I,J,bi,bj) - etaPre(I,J,bi,bj) = eta(I,J,bi,bj) - dwatPre(I,J,bi,bj) = DWATN(I,J,bi,bj) - pressPre(I,J,bi,bj) = press(I,J,bi,bj) + zetaPre(I,J,bi,bj) = zeta(I,J,bi,bj) + etaPre(I,J,bi,bj) = eta(I,J,bi,bj) + etaZPre(I,J,bi,bj) = etaZ(I,J,bi,bj) + dwatPre(I,J,bi,bj) = DWATN(I,J,bi,bj) ENDDO ENDDO 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 +C Important: Compute the norm of the residual using the same scalar +C product that SEAICE_FGMRES does + CALL SEAICE_MAP2VEC(nVec,uIceRes,vIceRes,resTmp,.TRUE.,myThid) + CALL SEAICE_SCALPROD( + & nVec,1,1,1,resTmp,resTmp,JFNKresidual,myThid) JFNKresidual = SQRT(JFNKresidual) C compute convergence criterion for linear preconditioned FGMRES JFNKgamma_lin = JFNKgamma_lin_max @@ -204,17 +189,6 @@ C in that routine krylovIter = 0 iCode = 0 - IF ( debugLevel.GE.debLevA ) THEN - _BEGIN_MASTER( myThid ) - WRITE(msgBuf,'(2A,2(1XI6),2E12.5)') - & ' S/R SEAICE_JFNK: newtonIter,', - & ' total newtonIter, JFNKgamma_lin, initial norm = ', - & newtonIter,SEAICEnewtonIterMax*(myIter-nIter0)+newtonIter, - & JFNKgamma_lin, JFNKresidual - CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, - & SQUEEZE_RIGHT, myThid ) - _END_MASTER( myThid ) - ENDIF C JFNKconverged = JFNKresidual.LT.JFNKtol C @@ -240,10 +214,11 @@ C or product of matrix (Jacobian) times vector. For iCode = 0, terminate C iteration IF (iCode.EQ.1) THEN -C Call preconditioner - CALL SEAICE_PRECONDITIONER( +C Call preconditioner + IF ( SOLV_MAX_ITERS .GT. 0 ) + & CALL SEAICE_PRECONDITIONER( U duIce, dvIce, - I zetaPre, etaPre, dwatPre, pressPre, + I zetaPre, etaPre, etaZpre, dwatPre, I newtonIter, krylovIter, myTime, myIter, myThid ) ELSEIF (iCode.GE.2) THEN C Compute Jacobian times vector @@ -259,9 +234,18 @@ C some output diagnostics IF ( debugLevel.GE.debLevA ) THEN _BEGIN_MASTER( myThid ) + totalNewtonItersLoc = + & SEAICEnewtonIterMax*(myIter-nIter0)+newtonIter + WRITE(msgBuf,'(2A,2(1XI6),2E12.5)') + & ' S/R SEAICE_JFNK: Newton iterate / total, ', + & 'JFNKgamma_lin, initial norm = ', + & newtonIter, totalNewtonItersLoc, + & JFNKgamma_lin,JFNKresidual + CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, + & SQUEEZE_RIGHT, myThid ) WRITE(msgBuf,'(3(A,I6))') - & ' S/R SEAICE_JFNK: Newton iterate / total = ', newtonIter, - & ' / ', SEAICEnewtonIterMax*(myIter-nIter0)+newtonIter, + & ' S/R SEAICE_JFNK: Newton iterate / total = ',newtonIter, + & ' / ', totalNewtonItersLoc, & ', Nb. of FGMRES iterations = ', krylovIter CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, & SQUEEZE_RIGHT, myThid ) @@ -292,18 +276,29 @@ C C-- Output diagnostics C + IF ( SEAICE_monFreq .GT. 0. _d 0 ) THEN C Count iterations - totalJFNKtimeSteps = totalJFNKtimeSteps + 1 - totalNewtonIters = totalNewtonIters + newtonIter - totalKrylovIters = totalKrylovIters + totalKrylovItersLoc + totalJFNKtimeSteps = totalJFNKtimeSteps + 1 + totalNewtonIters = totalNewtonIters + newtonIter + totalKrylovIters = totalKrylovIters + totalKrylovItersLoc C Record failure - totalKrylovFails = totalKrylovFails + krylovFails - IF ( newtonIter .EQ. SEAICEnewtonIterMax ) THEN - totalNewtonFails = totalNewtonFails + 1 + totalKrylovFails = totalKrylovFails + krylovFails + IF ( newtonIter .EQ. SEAICEnewtonIterMax ) THEN + totalNewtonFails = totalNewtonFails + 1 + ENDIF ENDIF C Decide whether it is time to dump and reset the counter - IF ( DIFFERENT_MULTIPLE(SEAICE_monFreq,myTime+deltaTClock, - & deltaTClock) ) THEN + writeNow = DIFFERENT_MULTIPLE(SEAICE_monFreq, + & myTime+deltaTClock, deltaTClock) +#ifdef ALLOW_CAL + IF ( useCAL ) THEN + CALL CAL_TIME2DUMP( + I zeroRL, SEAICE_monFreq, deltaTClock, + U writeNow, + I myTime+deltaTclock, myIter+1, myThid ) + ENDIF +#endif + IF ( writeNow ) THEN _BEGIN_MASTER( myThid ) WRITE(msgBuf,'(A)') &' // =======================================================' @@ -344,7 +339,7 @@ &' // =======================================================' CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, & SQUEEZE_RIGHT, myThid ) - WRITE(msgBuf,'(A)') ' // Begin JFNK statistics' + WRITE(msgBuf,'(A)') ' // End JFNK statistics' CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, & SQUEEZE_RIGHT, myThid ) WRITE(msgBuf,'(A)')