[petsc-users] Novice: How to implement the petsc Gmres libraries in my CFD code

Smith, Barry F. bsmith at mcs.anl.gov
Fri Jan 26 08:55:09 CST 2018

> On Jan 26, 2018, at 3:39 AM, Stephen Wornom <stephen.wornom at inria.fr> wrote:
> I am disparate to implement  the petsc library gmres in an CFD code and need a little help to get going.
> 23 years ago, gmres was implemented/written in the code by Y. Saad, modified by A. Malevsky, version February 1, 1995.

   Off by a decade or so.
> petsc, most likely started with the same version, added new solvers, ...etc and maintained and corrected bugs reported by users
> and I would like to use the latest petsc version of gmres
> Why?
> Normally we have no convergence problems using gmres.
> However sometimes gmres diverges instantaneously, no warning, just a negative density.

   A negative density likely has nothing to do with your gmres.  You should run your code with a very tight GMRES convergence tolerance and see what happens and how and when the density goes negative; put in debugging code in your solver and your GEMRES that checks for negative density at each step. Does a tighter tolerance lead to a later time for the negative density? 

   GMRES is GMRES, I don't think converting to the PETSc GMRES will make an difference with your negative density problem.

> Our code is parallel mpi, unstructured, uses a low Mach preconditioner, FV Roe scheme.
> Thus I would like to add an petsc option.
> Would  someone outline, in detail, the steps that I need to follow?
> I need all the encourage that I can get to add the option in the code.
> petsc is installed on our computers
> Thanks in advance,
> Stephen
>             IF ( petsc .EQ. 1 ) THEN
> c petsc        CALL MatAssembleBegin
> c petsc        CALL MatAssembleEnd
> ... add steps
>             ELSE
>                CALL GMRESASR ! from our code
>             ENDIF
> This is from our code which may be useful information
> c-----------------------------------------------------------------------
> c flexible GMRES routine. This is a version of GMRES which allows a 
> c a variable preconditioner. Implemented with a reverse communication 
> c protocole for flexibility -
> c explicit (exact) residual norms for restarts  
> c written by Y. Saad, modified by A. Malevsky, version February 1, 1995
> c-----------------------------------------------------------------------
> c This Is A Reverse Communication Implementation. 
> c------------------------------------------------- 
> c USAGE: (see also comments for icode below). CGMRES
> c should be put in a loop and the loop should be active for as
> c long as icode is not equal to 0. On RETURN fgmres will
> c    1) either be requesting the new preconditioned vector applied
> c       to wk1 in case icode.eq.1 (result should be put in wk2) 
> c    2) or be requesting the product of A applied to the vector wk1
> c       in case icode.eq.2 (result should be put in wk2) 
> c    3) or be terminated in case icode .eq. 0. 
> c on entry always set icode = 0. So icode should be set back to zero
> c upon convergence.
> c-----------------------------------------------------------------------
> c Here is a typical way of running fgmres: 
> c
> c      icode = 0
> c 1    continue
> c      CALL fgmres (n,im,rhs,sol,i,vv,w,wk1, wk2,eps,maxits,iout,icode)
> c
> c      if (icode .eq. 1) then
> c         CALL  precon(n, wk1, wk2)    <--- user's variable preconditioning
> c         goto 1
> c      else if (icode .ge. 2) then
> c         CALL  matvec (n,wk1, wk2)    <--- user's matrix vector product. 
> c         goto 1
> c      else 
> c         ----- done ---- 
> c         .........

More information about the petsc-users mailing list