Actual source code: gd.c

  1: /*
  2:   SLEPc eigensolver: "gd"

  4:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5:    SLEPc - Scalable Library for Eigenvalue Problem Computations
  6:    Copyright (c) 2002-2011, Universitat Politecnica de Valencia, Spain

  8:    This file is part of SLEPc.
  9:       
 10:    SLEPc is free software: you can redistribute it and/or modify it under  the
 11:    terms of version 3 of the GNU Lesser General Public License as published by
 12:    the Free Software Foundation.

 14:    SLEPc  is  distributed in the hope that it will be useful, but WITHOUT  ANY 
 15:    WARRANTY;  without even the implied warranty of MERCHANTABILITY or  FITNESS 
 16:    FOR  A  PARTICULAR PURPOSE. See the GNU Lesser General Public  License  for 
 17:    more details.

 19:    You  should have received a copy of the GNU Lesser General  Public  License
 20:    along with SLEPc. If not, see <http://www.gnu.org/licenses/>.
 21:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 22: */

 24:  #include private/epsimpl.h
 25: #include <../src/eps/impls/davidson/common/davidson.h>

 27: PetscErrorCode EPSSetUp_GD(EPS eps);
 28: PetscErrorCode EPSDestroy_GD(EPS eps);

 30: EXTERN_C_BEGIN
 33: PetscErrorCode EPSSetFromOptions_GD(EPS eps)
 34: {
 36:   PetscBool      flg,op;
 37:   PetscInt       opi,opi0;
 38:   KSP            ksp;

 41:   PetscOptionsHead("EPS Generalized Davidson (GD) Options");

 43:   EPSGDGetKrylovStart(eps,&op);
 44:   PetscOptionsBool("-eps_gd_krylov_start","Start the searching subspace with a krylov basis","EPSGDSetKrylovStart",op,&op,&flg);
 45:   if(flg) { EPSGDSetKrylovStart(eps,op); }

 47:   EPSGDGetBOrth(eps,&op);
 48:   PetscOptionsBool("-eps_gd_borth","B-orthogonalize the searching subspace basis","EPSGDSetBOrth",op,&op,&flg);
 49:   if(flg) { EPSGDSetBOrth(eps,op); }
 50: 
 51:   EPSGDGetBlockSize(eps,&opi);
 52:   PetscOptionsInt("-eps_gd_blocksize","Number vectors add to the searching subspace","EPSGDSetBlockSize",opi,&opi,&flg);
 53:   if(flg) { EPSGDSetBlockSize(eps,opi); }

 55:   EPSGDGetRestart(eps,&opi,&opi0);
 56:   PetscOptionsInt("-eps_gd_minv","Set the size of the searching subspace after restarting","EPSGDSetRestart",opi,&opi,&flg);
 57:   if(flg) { EPSGDSetRestart(eps,opi,opi0); }

 59:   PetscOptionsInt("-eps_gd_plusk","Set the number of saved eigenvectors from the previous iteration when restarting","EPSGDSetRestart",opi0,&opi0,&flg);
 60:   if(flg) { EPSGDSetRestart(eps,opi,opi0); }

 62:   EPSGDGetInitialSize(eps,&opi);
 63:   PetscOptionsInt("-eps_gd_initial_size","Set the initial size of the searching subspace","EPSGDSetInitialSize",opi,&opi,&flg);
 64:   if(flg) { EPSGDSetInitialSize(eps,opi); }

 66:   EPSGDGetWindowSizes(eps,&opi,&opi0);
 67:   PetscOptionsInt("-eps_gd_pwindow","(Experimental!) Set the number of converged vectors in the projector","EPSGDSetWindowSizes",opi,&opi,&flg);
 68:   if(flg) { EPSGDSetWindowSizes(eps,opi,opi0); }

 70:   PetscOptionsInt("-eps_gd_qwindow","(Experimental!) Set the number of converged vectors in the projected problem","EPSGDSetWindowSizes",opi0,&opi0,&flg);
 71:   if(flg) { EPSGDSetWindowSizes(eps,opi,opi0); }

 73:   PetscOptionsTail();

 75:   /* Set STPrecond as the default ST */
 76:   if (!((PetscObject)eps->OP)->type_name) {
 77:     STSetType(eps->OP,STPRECOND);
 78:   }
 79:   STPrecondSetKSPHasMat(eps->OP,PETSC_FALSE);

 81:   /* Set the default options of the KSP */
 82:   STGetKSP(eps->OP,&ksp);
 83:   if (!((PetscObject)ksp)->type_name) {
 84:     KSPSetType(ksp,KSPPREONLY);
 85:   }
 86: 
 87:   return(0);
 88: }
 89: EXTERN_C_END

 93: PetscErrorCode EPSSetUp_GD(EPS eps)
 94: {
 96:   PetscBool      t;
 97:   KSP            ksp;

100:   /* Setup common for all davidson solvers */
101:   EPSSetUp_Davidson(eps);

103:   /* Set KSPPREONLY as default */
104:   STGetKSP(eps->OP,&ksp);
105:   if (!((PetscObject)ksp)->type_name) {
106:     KSPSetType(ksp,KSPPREONLY);
107:   }
108: 
109:   /* Check some constraints */
110:   PetscTypeCompare((PetscObject)ksp,KSPPREONLY,&t);
111:   if (!t) SETERRQ(((PetscObject)eps)->comm,PETSC_ERR_SUP,"EPSGD only works with KSPPREONLY");
112:   return(0);
113: }

115: EXTERN_C_BEGIN
118: PetscErrorCode EPSCreate_GD(EPS eps)
119: {
120:   PetscErrorCode  ierr;

123:   /* Load the Davidson solver */
124:   EPSCreate_Davidson(eps);
125:   EPSDavidsonSetFix_Davidson(eps,0.0);

127:   /* Overload the GD properties */
128:   eps->ops->setfromoptions       = EPSSetFromOptions_GD;
129:   eps->ops->setup                = EPSSetUp_GD;
130:   eps->ops->destroy              = EPSDestroy_GD;

132:   PetscObjectComposeFunctionDynamic((PetscObject)eps,"EPSGDSetKrylovStart_C","EPSDavidsonSetKrylovStart_Davidson",EPSDavidsonSetKrylovStart_Davidson);
133:   PetscObjectComposeFunctionDynamic((PetscObject)eps,"EPSGDGetKrylovStart_C","EPSDavidsonGetKrylovStart_Davidson",EPSDavidsonGetKrylovStart_Davidson);
134:   PetscObjectComposeFunctionDynamic((PetscObject)eps,"EPSGDSetBOrth_C","EPSDavidsonSetBOrth_Davidson",EPSDavidsonSetBOrth_Davidson);
135:   PetscObjectComposeFunctionDynamic((PetscObject)eps,"EPSGDGetBOrth_C","EPSDavidsonGetBOrth_Davidson",EPSDavidsonGetBOrth_Davidson);
136:   PetscObjectComposeFunctionDynamic((PetscObject)eps,"EPSGDSetBlockSize_C","EPSDavidsonSetBlockSize_Davidson",EPSDavidsonSetBlockSize_Davidson);
137:   PetscObjectComposeFunctionDynamic((PetscObject)eps,"EPSGDGetBlockSize_C","EPSDavidsonGetBlockSize_Davidson",EPSDavidsonGetBlockSize_Davidson);
138:   PetscObjectComposeFunctionDynamic((PetscObject)eps,"EPSGDSetRestart_C","EPSDavidsonSetRestart_Davidson",EPSDavidsonSetRestart_Davidson);
139:   PetscObjectComposeFunctionDynamic((PetscObject)eps,"EPSGDGetRestart_C","EPSDavidsonGetRestart_Davidson",EPSDavidsonGetRestart_Davidson);
140:   PetscObjectComposeFunctionDynamic((PetscObject)eps,"EPSGDSetInitialSize_C","EPSDavidsonSetInitialSize_Davidson",EPSDavidsonSetInitialSize_Davidson);
141:   PetscObjectComposeFunctionDynamic((PetscObject)eps,"EPSGDGetInitialSize_C","EPSDavidsonGetInitialSize_Davidson",EPSDavidsonGetInitialSize_Davidson);
142:   PetscObjectComposeFunctionDynamic((PetscObject)eps,"EPSGDSetWindowSizes_C","EPSDavidsonSetWindowSizes_Davidson",EPSDavidsonSetWindowSizes_Davidson);
143:   PetscObjectComposeFunctionDynamic((PetscObject)eps,"EPSGDGetWindowSizes_C","EPSDavidsonGetWindowSizes_Davidson",EPSDavidsonGetWindowSizes_Davidson);
144:   return(0);
145: }
146: EXTERN_C_END

150: PetscErrorCode EPSDestroy_GD(EPS eps)
151: {
152:   PetscErrorCode  ierr;

155:   PetscFree(eps->data);
156:   PetscObjectComposeFunctionDynamic((PetscObject)eps,"EPSGDSetKrylovStart_C","",PETSC_NULL);
157:   PetscObjectComposeFunctionDynamic((PetscObject)eps,"EPSGDGetKrylovStart_C","",PETSC_NULL);
158:   PetscObjectComposeFunctionDynamic((PetscObject)eps,"EPSGDSetBOrth_C","",PETSC_NULL);
159:   PetscObjectComposeFunctionDynamic((PetscObject)eps,"EPSGDGetBOrth_C","",PETSC_NULL);
160:   PetscObjectComposeFunctionDynamic((PetscObject)eps,"EPSGDSetBlockSize_C","",PETSC_NULL);
161:   PetscObjectComposeFunctionDynamic((PetscObject)eps,"EPSGDGetBlockSize_C","",PETSC_NULL);
162:   PetscObjectComposeFunctionDynamic((PetscObject)eps,"EPSGDSetRestart_C","",PETSC_NULL);
163:   PetscObjectComposeFunctionDynamic((PetscObject)eps,"EPSGDGetRestart_C","",PETSC_NULL);
164:   PetscObjectComposeFunctionDynamic((PetscObject)eps,"EPSGDSetInitialSize_C","",PETSC_NULL);
165:   PetscObjectComposeFunctionDynamic((PetscObject)eps,"EPSGDGetInitialSize_C","",PETSC_NULL);
166:   PetscObjectComposeFunctionDynamic((PetscObject)eps,"EPSGDSetWindowSizes_C","",PETSC_NULL);
167:   PetscObjectComposeFunctionDynamic((PetscObject)eps,"EPSGDGetWindowSizes_C","",PETSC_NULL);
168:   return(0);
169: }

173: /*@
174:    EPSGDSetKrylovStart - Activates or deactivates starting the searching
175:    subspace with a Krylov basis. 

177:    Logically Collective on EPS

179:    Input Parameters:
180: +  eps - the eigenproblem solver context
181: -  krylovstart - boolean flag

183:    Options Database Key:
184: .  -eps_gd_krylov_start - Activates starting the searching subspace with a
185:     Krylov basis
186:    
187:    Level: advanced

189: .seealso: EPSGDGetKrylovStart()
190: @*/
191: PetscErrorCode EPSGDSetKrylovStart(EPS eps,PetscBool krylovstart)
192: {

198:   PetscTryMethod(eps,"EPSGDSetKrylovStart_C",(EPS,PetscBool),(eps,krylovstart));
199:   return(0);
200: }

204: /*@
205:    EPSGDGetKrylovStart - Returns a flag indicating if the search subspace is started with a
206:    Krylov basis.

208:    Not Collective

210:    Input Parameter:
211: .  eps - the eigenproblem solver context

213:    Output Parameters:
214: .  krylovstart - boolean flag indicating if the search subspace is started
215:    with a Krylov basis

217:    Level: advanced

219: .seealso: EPSGDGetKrylovStart()
220: @*/
221: PetscErrorCode EPSGDGetKrylovStart(EPS eps,PetscBool *krylovstart)
222: {

228:   PetscTryMethod(eps,"EPSGDGetKrylovStart_C",(EPS,PetscBool*),(eps,krylovstart));
229:   return(0);
230: }

234: /*@
235:    EPSGDSetBlockSize - Sets the number of vectors to be added to the searching space
236:    in every iteration.

238:    Logically Collective on EPS

240:    Input Parameters:
241: +  eps - the eigenproblem solver context
242: -  blocksize - number of vectors added to the search space in every iteration

244:    Options Database Key:
245: .  -eps_gd_blocksize - number of vectors added to the search space in every iteration
246:    
247:    Level: advanced

249: .seealso: EPSGDSetKrylovStart()
250: @*/
251: PetscErrorCode EPSGDSetBlockSize(EPS eps,PetscInt blocksize)
252: {

258:   PetscTryMethod(eps,"EPSGDSetBlockSize_C",(EPS,PetscInt),(eps,blocksize));
259:   return(0);
260: }

264: /*@
265:    EPSGDGetBlockSize - Returns the number of vectors to be added to the searching space
266:    in every iteration.

268:    Not Collective

270:    Input Parameter:
271: .  eps - the eigenproblem solver context

273:    Output Parameter:
274: .  blocksize - number of vectors added to the search space in every iteration

276:    Level: advanced

278: .seealso: EPSGDSetBlockSize()
279: @*/
280: PetscErrorCode EPSGDGetBlockSize(EPS eps,PetscInt *blocksize)
281: {

287:   PetscTryMethod(eps,"EPSGDGetBlockSize_C",(EPS,PetscInt*),(eps,blocksize));
288:   return(0);
289: }

293: /*@
294:    EPSGDGetRestart - Gets the number of vectors of the searching space after
295:    restarting and the number of vectors saved from the previous iteration.

297:    Not Collective

299:    Input Parameter:
300: .  eps - the eigenproblem solver context

302:    Output Parameter:
303: +  minv - number of vectors of the searching subspace after restarting
304: -  plusk - number of vectors saved from the previous iteration   

306:    Level: advanced

308: .seealso: EPSGDSetRestart()
309: @*/
310: PetscErrorCode EPSGDGetRestart(EPS eps,PetscInt *minv,PetscInt *plusk)
311: {

318:   PetscTryMethod(eps,"EPSGDGetRestart_C",(EPS,PetscInt*,PetscInt*),(eps,minv,plusk));
319:   return(0);
320: }

324: /*@
325:    EPSGDSetRestart - Sets the number of vectors of the searching space after
326:    restarting and the number of vectors saved from the previous iteration.

328:    Logically Collective on EPS

330:    Input Parameters:
331: +  eps - the eigenproblem solver context
332: .  minv - number of vectors of the searching subspace after restarting
333: -  plusk - number of vectors saved from the previous iteration   

335:    Options Database Keys:
336: +  -eps_gd_minv - number of vectors of the searching subspace after restarting
337: -  -eps_gd_plusk - number of vectors saved from the previous iteration   
338:    
339:    Level: advanced

341: .seealso: EPSGDSetRestart()
342: @*/
343: PetscErrorCode EPSGDSetRestart(EPS eps,PetscInt minv,PetscInt plusk)
344: {

351:   PetscTryMethod(eps,"EPSGDSetRestart_C",(EPS,PetscInt,PetscInt),(eps,minv,plusk));
352:   return(0);
353: }

357: /*@
358:    EPSGDGetInitialSize - Returns the initial size of the searching space.

360:    Not Collective

362:    Input Parameter:
363: .  eps - the eigenproblem solver context

365:    Output Parameter:
366: .  initialsize - number of vectors of the initial searching subspace

368:    Notes:
369:    If EPSGDGetKrylovStart() is PETSC_FALSE and the user provides vectors with
370:    EPSSetInitialSpace(), up to initialsize vectors will be used; and if the
371:    provided vectors are not enough, the solver completes the subspace with
372:    random vectors. In the case of EPSGDGetKrylovStart() being PETSC_TRUE, the solver
373:    gets the first vector provided by the user or, if not available, a random vector,
374:    and expands the Krylov basis up to initialsize vectors.

376:    Level: advanced

378: .seealso: EPSGDSetInitialSize(), EPSGDGetKrylovStart()
379: @*/
380: PetscErrorCode EPSGDGetInitialSize(EPS eps,PetscInt *initialsize)
381: {

387:   PetscTryMethod(eps,"EPSGDGetInitialSize_C",(EPS,PetscInt*),(eps,initialsize));
388:   return(0);
389: }

393: /*@
394:    EPSGDSetInitialSize - Sets the initial size of the searching space.

396:    Logically Collective on EPS

398:    Input Parameters:
399: +  eps - the eigenproblem solver context
400: -  initialsize - number of vectors of the initial searching subspace

402:    Options Database Key:
403: .  -eps_gd_initial_size - number of vectors of the initial searching subspace
404:    
405:    Notes:
406:    If EPSGDGetKrylovStart() is PETSC_FALSE and the user provides vectors with
407:    EPSSetInitialSpace(), up to initialsize vectors will be used; and if the
408:    provided vectors are not enough, the solver completes the subspace with
409:    random vectors. In the case of EPSGDGetKrylovStart() being PETSC_TRUE, the solver
410:    gets the first vector provided by the user or, if not available, a random vector,
411:    and expands the Krylov basis up to initialsize vectors.

413:    Level: advanced

415: .seealso: EPSGDGetInitialSize(), EPSGDGetKrylovStart()
416: @*/
417: PetscErrorCode EPSGDSetInitialSize(EPS eps,PetscInt initialsize)
418: {

424:   PetscTryMethod(eps,"EPSGDSetInitialSize_C",(EPS,PetscInt),(eps,initialsize));
425:   return(0);
426: }

430: /*@
431:    EPSGDSetBOrth - Activates or deactivates the B-orthogonalizetion of the searching
432:    subspace in case of generalized Hermitian problems.

434:    Logically Collective on EPS

436:    Input Parameters:
437: +  eps - the eigenproblem solver context
438: -  borth - boolean flag

440:    Options Database Key:
441: .  -eps_gd_borth - Activates the B-orthogonalization of the searching subspace
442:    
443:    Level: advanced

445: .seealso: EPSGDGetBOrth()
446: @*/
447: PetscErrorCode EPSGDSetBOrth(EPS eps,PetscBool borth)
448: {

454:   PetscTryMethod(eps,"EPSGDSetBOrth_C",(EPS,PetscBool),(eps,borth));
455:   return(0);
456: }

460: /*@
461:    EPSGDGetBOrth - Returns a flag indicating if the search subspace basis is
462:    B-orthogonalized.

464:    Not Collective

466:    Input Parameter:
467: .  eps - the eigenproblem solver context

469:    Output Parameters:
470: .  borth - the boolean flag

472:    Level: advanced

474: .seealso: EPSGDGetKrylovStart()
475: @*/
476: PetscErrorCode EPSGDGetBOrth(EPS eps,PetscBool *borth)
477: {

483:   PetscTryMethod(eps,"EPSGDGetBOrth_C",(EPS,PetscBool*),(eps,borth));
484:   return(0);
485: }

489: /*@
490:    EPSGDGetWindowSizes - Gets the number of converged vectors in the projected
491:    problem (or Rayleigh quotient) and in the projector employed in the correction
492:    equation.

494:    Not Collective

496:    Input Parameter:
497: .  eps - the eigenproblem solver context

499:    Output Parameter:
500: +  pwindow - number of converged vectors in the projector
501: -  qwindow - number of converged vectors in the projected problem

503:    Level: advanced

505: .seealso: EPSGDSetWindowSizes()
506: @*/
507: PetscErrorCode EPSGDGetWindowSizes(EPS eps,PetscInt *pwindow,PetscInt *qwindow)
508: {

515:   PetscTryMethod(eps,"EPSGDGetWindowSizes_C",(EPS,PetscInt*,PetscInt*),(eps,pwindow,qwindow));
516:   return(0);
517: }

521: /*@
522:    EPSGDSetWindowSizes - Sets the number of converged vectors in the projected
523:    problem (or Rayleigh quotient) and in the projector employed in the correction
524:    equation.

526:    Logically Collective on EPS

528:    Input Parameters:
529: +  eps - the eigenproblem solver context
530: .  pwindow - number of converged vectors in the projector
531: -  qwindow - number of converged vectors in the projected problem

533:    Options Database Keys:
534: +  -eps_gd_pwindow - set the number of converged vectors in the projector
535: -  -eps_gd_qwindow - set the number of converged vectors in the projected problem  
536:    
537:    Level: advanced

539: .seealso: EPSGDGetWindowSizes()
540: @*/
541: PetscErrorCode EPSGDSetWindowSizes(EPS eps,PetscInt pwindow,PetscInt qwindow)
542: {

549:   PetscTryMethod(eps,"EPSGDSetWindowSizes_C",(EPS,PetscInt,PetscInt),(eps,pwindow,qwindow));
550:   return(0);
551: }