Actual source code: gmres2.c

  1: /*$Id: gmres2.c,v 1.34 2001/04/10 19:36:32 bsmith Exp $*/
  2: #include "src/sles/ksp/impls/gmres/gmresp.h"       /*I  "petscksp.h"  I*/

  4: /*@
  5:     KSPGMRESSetHapTol - Sets the tolerence for GMRES to declare happy breakdown.
  6:     for GMRES before restart.

  8:     Collective on KSP

 10:     Input Parameters:
 11: +   ksp - the iterative context
 12: -   tol - the tolerance (1.e-10 is the default)

 14:     Options Database Key:
 15: .   -ksp_gmres_haptol <tol>

 17:     Level: advanced

 19: .keywords: KSP, GMRES, set, happy breakdown

 21: .seealso: KSPGMRESSetOrthogonalization(), KSPGMRESSetPreallocateVectors()
 22: @*/
 23: int KSPGMRESSetHapTol(KSP ksp,double tol)
 24: {
 25:   int ierr,(*f)(KSP,double);

 29:   if (tol < 0.0) SETERRQ(1,"Tolerance must be non-negative");
 30:   PetscObjectQueryFunction((PetscObject)ksp,"KSPGMRESSetHapTol_C",(void (**)())&f);
 31:   if (f) {
 32:     (*f)(ksp,tol);
 33:   }

 35:   return(0);
 36: }

 38: /*@
 39:     KSPGMRESSetRestart - Sets the number of search directions 
 40:     for GMRES before restart.

 42:     Collective on KSP

 44:     Input Parameters:
 45: +   ksp - the iterative context
 46: -   max_k - the number of directions

 48:     Options Database Key:
 49: .   -ksp_gmres_restart <max_k> - Sets max_k

 51:     Level: intermediate

 53:     Note:
 54:     The default value of max_k = 30.

 56: .keywords: KSP, GMRES, set, restart

 58: .seealso: KSPGMRESSetOrthogonalization(), KSPGMRESSetPreallocateVectors()
 59: @*/
 60: int KSPGMRESSetRestart(KSP ksp,int max_k)
 61: {
 62:   int ierr,(*f)(KSP,int);

 66:   if (max_k < 1) SETERRQ(1,"Restart must be positive");
 67:   PetscObjectQueryFunction((PetscObject)ksp,"KSPGMRESSetRestart_C",(void (**)())&f);
 68:   if (f) {
 69:     (*f)(ksp,max_k);
 70:   }

 72:   return(0);
 73: }

 75: /*@C
 76:    KSPGMRESSetOrthogonalization - Sets the orthogonalization routine used by GMRES.

 78:    Collective on KSP

 80:    Input Parameters:
 81: +  ksp - iterative context obtained from KSPCreate
 82: -  fcn - orthogonalization function

 84:    Calling Sequence of function:
 85: $   errorcode = int fcn(KSP ksp,int it);
 86: $   it is one minus the number of GMRES iterations since last restart;
 87: $    i.e. the size of Krylov space minus one

 89:    Notes:
 90:    Several orthogonalization routines are predefined, including

 92:    KSPGMRESModifiedGramSchmidtOrthogonalization()

 94:    KSPGMRESUnmodifiedGramSchmidtOrthogonalization() - 
 95:        NOT recommended; however, for some problems, particularly
 96:        when using parallel distributed vectors, this may be
 97:        significantly faster. Default.

 99:    KSPGMRESIROrthogonalization() - iterative refinement
100:        version of KSPGMRESUnmodifiedGramSchmidtOrthogonalization(),
101:        which may be more numerically stable.

103:    Options Database Keys:

105: +  -ksp_gmres_unmodifiedgramschmidt - Activates KSPGMRESUnmodifiedGramSchmidtOrthogonalization() (default)
106: .  -ksp_gmres_modifiedgramschmidt - Activates KSPGMRESModifiedGramSchmidtOrthogonalization()
107: -  -ksp_gmres_irorthog - Activates KSPGMRESIROrthogonalization()

109:    Level: intermediate

111: .keywords: KSP, GMRES, set, orthogonalization, Gram-Schmidt, iterative refinement

113: .seealso: KSPGMRESSetRestart(), KSPGMRESSetPreallocateVectors()
114: @*/
115: int KSPGMRESSetOrthogonalization(KSP ksp,int (*fcn)(KSP,int))
116: {
117:   int ierr,(*f)(KSP,int (*)(KSP,int));

121:   PetscObjectQueryFunction((PetscObject)ksp,"KSPGMRESSetOrthogonalization_C",(void (**)())&f);
122:   if (f) {
123:     (*f)(ksp,fcn);
124:   }
125:   return(0);
126: }