| 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 |
| 60 |
LOGICAL DIFFERENT_MULTIPLE |
LOGICAL DIFFERENT_MULTIPLE |
| 61 |
EXTERNAL DIFFERENT_MULTIPLE |
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 |
| 149 |
newtonIter = newtonIter + 1 |
newtonIter = newtonIter + 1 |
| 150 |
C Compute initial residual F(u), (includes computation of global |
C Compute initial residual F(u), (includes computation of global |
| 151 |
C variables DWATN, zeta, and eta) |
C variables DWATN, zeta, and eta) |
| 152 |
CALL SEAICE_CALC_RESIDUAL( |
IF ( newtonIter .EQ. 1 ) CALL SEAICE_JFNK_UPDATE( |
| 153 |
I uIce, vIce, |
I duIce, dvIce, |
| 154 |
O uIceRes, vIceRes, |
U uIce, vIce, JFNKresidual, |
| 155 |
I newtonIter, 0, myTime, myIter, myThid ) |
O uIceRes, vIceRes, |
| 156 |
C probably not necessary, will be removed later: |
I newtonIter, myTime, myIter, myThid ) |
|
CALL EXCH_UV_XY_RL( uIceRes, vIceRes,.TRUE.,myThid) |
|
| 157 |
C local copies of precomputed coefficients that are to stay |
C local copies of precomputed coefficients that are to stay |
| 158 |
C constant for the preconditioner |
C constant for the preconditioner |
| 159 |
DO bj=myByLo(myThid),myByHi(myThid) |
DO bj=myByLo(myThid),myByHi(myThid) |
| 168 |
ENDDO |
ENDDO |
| 169 |
ENDDO |
ENDDO |
| 170 |
ENDDO |
ENDDO |
|
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) |
|
| 171 |
C compute convergence criterion for linear preconditioned FGMRES |
C compute convergence criterion for linear preconditioned FGMRES |
| 172 |
JFNKgamma_lin = JFNKgamma_lin_max |
JFNKgamma_lin = JFNKgamma_lin_max |
| 173 |
IF ( newtonIter.GT.1.AND.newtonIter.LE.100 |
IF ( newtonIter.GT.1.AND.newtonIter.LE.100 |
| 254 |
IF ( krylovIter.EQ.SEAICEkrylovIterMax ) THEN |
IF ( krylovIter.EQ.SEAICEkrylovIterMax ) THEN |
| 255 |
krylovFails = krylovFails + 1 |
krylovFails = krylovFails + 1 |
| 256 |
ENDIF |
ENDIF |
| 257 |
|
C Set the stopping criterion for the Newton iteration |
| 258 |
|
IF ( newtonIter .EQ. 1 ) JFNKtol=JFNKgamma_nonlin*JFNKresidual |
| 259 |
C Update linear solution vector and return to Newton iteration |
C Update linear solution vector and return to Newton iteration |
| 260 |
|
C Do a linesearch if necessary, and compute a new residual. |
| 261 |
|
C Note that it should be possible to do the following operations |
| 262 |
|
C at the beginning of the Newton iteration, thereby saving us from |
| 263 |
|
C the extra call of seaice_jfnk_update, but unfortunately that |
| 264 |
|
C changes the results, so we leave the stuff here for now. |
| 265 |
|
CALL SEAICE_JFNK_UPDATE( |
| 266 |
|
I duIce, dvIce, |
| 267 |
|
U uIce, vIce, JFNKresidual, |
| 268 |
|
O uIceRes, vIceRes, |
| 269 |
|
I newtonIter, myTime, myIter, myThid ) |
| 270 |
|
C reset du/vIce here instead of setting sol = 0 in seaice_fgmres_driver |
| 271 |
DO bj=myByLo(myThid),myByHi(myThid) |
DO bj=myByLo(myThid),myByHi(myThid) |
| 272 |
DO bi=myBxLo(myThid),myBxHi(myThid) |
DO bi=myBxLo(myThid),myBxHi(myThid) |
| 273 |
DO J=1-Oly,sNy+Oly |
DO J=1-Oly,sNy+Oly |
| 274 |
DO I=1-Olx,sNx+Olx |
DO I=1-Olx,sNx+Olx |
|
uIce(I,J,bi,bj) = uIce(I,J,bi,bj)+duIce(I,J,bi,bj) |
|
|
vIce(I,J,bi,bj) = vIce(I,J,bi,bj)+dvIce(I,J,bi,bj) |
|
|
C reset du/vIce here instead of setting sol = 0 in seaice_fgmres_driver |
|
| 275 |
duIce(I,J,bi,bj)= 0. _d 0 |
duIce(I,J,bi,bj)= 0. _d 0 |
| 276 |
dvIce(I,J,bi,bj)= 0. _d 0 |
dvIce(I,J,bi,bj)= 0. _d 0 |
| 277 |
ENDDO |
ENDDO |
| 278 |
ENDDO |
ENDDO |
| 279 |
ENDDO |
ENDDO |
| 280 |
ENDDO |
ENDDO |
|
C Set the stopping criterion for the Newton iteration |
|
|
IF ( newtonIter .EQ. 1 ) JFNKtol=JFNKgamma_nonlin*JFNKresidual |
|
| 281 |
ENDIF |
ENDIF |
| 282 |
C end of Newton iterate |
C end of Newton iterate |
| 283 |
ENDDO |
ENDDO |
| 392 |
_END_MASTER( myThid ) |
_END_MASTER( myThid ) |
| 393 |
ENDIF |
ENDIF |
| 394 |
|
|
| 395 |
|
RETURN |
| 396 |
|
END |
| 397 |
|
|
| 398 |
|
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
| 399 |
|
CBOP |
| 400 |
|
C !ROUTINE: SEAICE_JFNK_UPDATE |
| 401 |
|
C !INTERFACE: |
| 402 |
|
|
| 403 |
|
SUBROUTINE SEAICE_JFNK_UPDATE( |
| 404 |
|
I duIce, dvIce, |
| 405 |
|
U uIce, vIce, JFNKresidual, |
| 406 |
|
O uIceRes, vIceRes, |
| 407 |
|
I newtonIter, myTime, myIter, myThid ) |
| 408 |
|
|
| 409 |
|
C !DESCRIPTION: \bv |
| 410 |
|
C *==========================================================* |
| 411 |
|
C | SUBROUTINE SEAICE_JFNK_UPDATE |
| 412 |
|
C | o Update velocities with incremental solutions of FGMRES |
| 413 |
|
C | o compute residual of updated solutions and do |
| 414 |
|
C | o linesearch: |
| 415 |
|
C | reduce update until residual is smaller than previous |
| 416 |
|
C | one (input) |
| 417 |
|
C *==========================================================* |
| 418 |
|
C | written by Martin Losch, Jan 2013 |
| 419 |
|
C *==========================================================* |
| 420 |
|
C \ev |
| 421 |
|
|
| 422 |
|
C !USES: |
| 423 |
|
IMPLICIT NONE |
| 424 |
|
|
| 425 |
|
C === Global variables === |
| 426 |
|
#include "SIZE.h" |
| 427 |
|
#include "EEPARAMS.h" |
| 428 |
|
#include "PARAMS.h" |
| 429 |
|
#include "SEAICE_SIZE.h" |
| 430 |
|
#include "SEAICE_PARAMS.h" |
| 431 |
|
|
| 432 |
|
C !INPUT/OUTPUT PARAMETERS: |
| 433 |
|
C === Routine arguments === |
| 434 |
|
C myTime :: Simulation time |
| 435 |
|
C myIter :: Simulation timestep number |
| 436 |
|
C myThid :: my Thread Id. number |
| 437 |
|
C newtonIter :: current iterate of Newton iteration |
| 438 |
|
_RL myTime |
| 439 |
|
INTEGER myIter |
| 440 |
|
INTEGER myThid |
| 441 |
|
INTEGER newtonIter |
| 442 |
|
C JFNKresidual :: Residual at the beginning of the FGMRES iteration, |
| 443 |
|
C changes with newtonIter (updated) |
| 444 |
|
_RL JFNKresidual |
| 445 |
|
C du/vIce :: ice velocity increment to be added to u/vIce (input) |
| 446 |
|
_RL duIce (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy) |
| 447 |
|
_RL dvIce (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy) |
| 448 |
|
C u/vIce :: ice velocity increment to be added to u/vIce (updated) |
| 449 |
|
_RL uIce (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy) |
| 450 |
|
_RL vIce (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy) |
| 451 |
|
C u/vIceRes :: residual of sea-ice momentum equations (output) |
| 452 |
|
_RL uIceRes(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy) |
| 453 |
|
_RL vIceRes(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy) |
| 454 |
|
|
| 455 |
|
C !LOCAL VARIABLES: |
| 456 |
|
C === Local variables === |
| 457 |
|
C i,j,bi,bj :: loop indices |
| 458 |
|
INTEGER i,j,bi,bj |
| 459 |
|
INTEGER l |
| 460 |
|
_RL resLoc, facLS |
| 461 |
|
LOGICAL doLineSearch |
| 462 |
|
C nVec :: size of the input vector(s) |
| 463 |
|
C vector version of the residuals |
| 464 |
|
INTEGER nVec |
| 465 |
|
PARAMETER ( nVec = 2*sNx*sNy ) |
| 466 |
|
_RL resTmp (nVec,1,nSx,nSy) |
| 467 |
|
C |
| 468 |
|
CHARACTER*(MAX_LEN_MBUF) msgBuf |
| 469 |
|
CEOP |
| 470 |
|
|
| 471 |
|
C Initialise some local variables |
| 472 |
|
l = 0 |
| 473 |
|
resLoc = JFNKresidual |
| 474 |
|
facLS = 1. _d 0 |
| 475 |
|
doLineSearch = .TRUE. |
| 476 |
|
DO WHILE ( doLineSearch ) |
| 477 |
|
C Determine, if we need more iterations |
| 478 |
|
doLineSearch = resLoc .GE. JFNKresidual |
| 479 |
|
C Limit the maximum number of iterations arbitrarily to four |
| 480 |
|
doLineSearch = doLineSearch .AND. l .LE. 4 |
| 481 |
|
C For the first iteration du/vIce = 0 and there will be no |
| 482 |
|
C improvement of the residual possible, so we do only the first |
| 483 |
|
C iteration |
| 484 |
|
IF ( newtonIter .EQ. 1 ) doLineSearch = .FALSE. |
| 485 |
|
C Only start a linesearch after some Newton iterations |
| 486 |
|
IF ( newtonIter .LE. SEAICE_JFNK_lsIter ) doLineSearch = .FALSE. |
| 487 |
|
C Increment counter |
| 488 |
|
l = l + 1 |
| 489 |
|
C Create update |
| 490 |
|
DO bj=myByLo(myThid),myByHi(myThid) |
| 491 |
|
DO bi=myBxLo(myThid),myBxHi(myThid) |
| 492 |
|
DO J=1-Oly,sNy+Oly |
| 493 |
|
DO I=1-Olx,sNx+Olx |
| 494 |
|
uIce(I,J,bi,bj) = uIce(I,J,bi,bj)+facLS*duIce(I,J,bi,bj) |
| 495 |
|
vIce(I,J,bi,bj) = vIce(I,J,bi,bj)+facLS*dvIce(I,J,bi,bj) |
| 496 |
|
ENDDO |
| 497 |
|
ENDDO |
| 498 |
|
ENDDO |
| 499 |
|
ENDDO |
| 500 |
|
C Compute current residual F(u), (includes re-computation of global |
| 501 |
|
C variables DWATN, zeta, and eta, i.e. they are different after this) |
| 502 |
|
CALL SEAICE_CALC_RESIDUAL( |
| 503 |
|
I uIce, vIce, |
| 504 |
|
O uIceRes, vIceRes, |
| 505 |
|
I newtonIter, 0, myTime, myIter, myThid ) |
| 506 |
|
C Important: Compute the norm of the residual using the same scalar |
| 507 |
|
C product that SEAICE_FGMRES does |
| 508 |
|
CALL SEAICE_MAP2VEC(nVec,uIceRes,vIceRes,resTmp,.TRUE.,myThid) |
| 509 |
|
CALL SEAICE_SCALPROD(nVec,1,1,1,resTmp,resTmp,resLoc,myThid) |
| 510 |
|
resLoc = SQRT(resLoc) |
| 511 |
|
C some output diagnostics |
| 512 |
|
IF ( debugLevel.GE.debLevA .AND. doLineSearch ) THEN |
| 513 |
|
_BEGIN_MASTER( myThid ) |
| 514 |
|
WRITE(msgBuf,'(2A,2(1XI6),3E12.5)') |
| 515 |
|
& ' S/R SEAICE_JFNK_UPDATE: Newton iter, LSiter, ', |
| 516 |
|
& 'facLS, JFNKresidual, resLoc = ', |
| 517 |
|
& newtonIter, l, facLS, JFNKresidual, resLoc |
| 518 |
|
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
| 519 |
|
& SQUEEZE_RIGHT, myThid ) |
| 520 |
|
_END_MASTER( myThid ) |
| 521 |
|
ENDIF |
| 522 |
|
C Get ready for the next iteration: after adding du/vIce in the first |
| 523 |
|
C iteration, we substract 0.5*du/vIce from u/vIce in the next |
| 524 |
|
C iterations, 0.25*du/vIce in the second, etc. |
| 525 |
|
facLS = - 0.5 _d 0 * ABS(facLS) |
| 526 |
|
ENDDO |
| 527 |
|
C This is the new residual |
| 528 |
|
JFNKresidual = resLoc |
| 529 |
|
|
| 530 |
#endif /* SEAICE_ALLOW_DYNAMICS and SEAICE_CGRID and SEAICE_ALLOW_JFNK */ |
#endif /* SEAICE_ALLOW_DYNAMICS and SEAICE_CGRID and SEAICE_ALLOW_JFNK */ |
| 531 |
|
|
| 532 |
RETURN |
RETURN |