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);

 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: }

 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: }

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

123:   /* Load the Davidson solver */
124:   EPSCreate_Davidson(eps);

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

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

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

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

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

176:    Logically Collective on EPS

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

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

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

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

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

207:    Not Collective

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

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

216:    Level: advanced

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

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

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

237:    Logically Collective on EPS

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

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

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

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

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

267:    Not Collective

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

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

275:    Level: advanced

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

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

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

296:    Not Collective

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

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

305:    Level: advanced

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

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

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

327:    Logically Collective on EPS

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

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

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

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

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

359:    Not Collective

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

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

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

375:    Level: advanced

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

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

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

395:    Logically Collective on EPS

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

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

412:    Level: advanced

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

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

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

433:    Logically Collective on EPS

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

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

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

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

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

463:    Not Collective

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

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

471:    Level: advanced

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

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

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

493:    Not Collective

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

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

502:    Level: advanced

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

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

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

525:    Logically Collective on EPS

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

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

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

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