Actual source code: davidson.c
1: /*
2: Method: General Davidson Method (includes GD and JD)
4: References:
5: - Ernest R. Davidson. Super-matrix methods. Computer Physics Communications,
6: 53:49–60, May 1989.
8: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
9: SLEPc - Scalable Library for Eigenvalue Problem Computations
10: Copyright (c) 2002-2011, Universitat Politecnica de Valencia, Spain
12: This file is part of SLEPc.
13:
14: SLEPc is free software: you can redistribute it and/or modify it under the
15: terms of version 3 of the GNU Lesser General Public License as published by
16: the Free Software Foundation.
18: SLEPc is distributed in the hope that it will be useful, but WITHOUT ANY
19: WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20: FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
21: more details.
23: You should have received a copy of the GNU Lesser General Public License
24: along with SLEPc. If not, see <http://www.gnu.org/licenses/>.
25: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
26: */
28: #include davidson.h
30: PetscErrorCode EPSView_Davidson(EPS eps,PetscViewer viewer);
32: typedef struct {
33: /**** Solver options ****/
34: PetscInt blocksize, /* block size */
35: initialsize, /* initial size of V */
36: minv, /* size of V after restarting */
37: plusk; /* keep plusk eigenvectors from the last iteration */
38: PetscBool ipB; /* true if V'B*V=I */
39: PetscInt method; /* method for improving the approximate solution */
40: PetscReal fix; /* the fix parameter */
41: PetscBool krylovstart; /* true if the starting subspace is a Krylov basis */
42: PetscBool dynamic; /* true if dynamic stopping criterion is used */
43: PetscInt cX_in_proj, /* converged vectors in the projected problem */
44: cX_in_impr; /* converged vectors in the projector */
46: /**** Solver data ****/
47: dvdDashboard ddb;
49: /**** Things to destroy ****/
50: PetscScalar *wS;
51: Vec *wV;
52: PetscInt size_wV;
53: } EPS_DAVIDSON;
57: PetscErrorCode EPSCreate_Davidson(EPS eps)
58: {
60: EPS_DAVIDSON *data;
64: eps->OP->ops->getbilinearform = STGetBilinearForm_Default;
65: eps->ops->solve = EPSSolve_Davidson;
66: eps->ops->setup = EPSSetUp_Davidson;
67: eps->ops->reset = EPSReset_Davidson;
68: eps->ops->backtransform = EPSBackTransform_Default;
69: eps->ops->computevectors = EPSComputeVectors_Davidson;
70: eps->ops->view = EPSView_Davidson;
72: PetscMalloc(sizeof(EPS_DAVIDSON),&data);
73: eps->data = data;
74: data->wS = PETSC_NULL;
75: data->wV = PETSC_NULL;
76: data->size_wV = 0;
77: PetscMemzero(&data->ddb,sizeof(dvdDashboard));
79: /* Set default values */
80: EPSDavidsonSetKrylovStart_Davidson(eps,PETSC_FALSE);
81: EPSDavidsonSetBlockSize_Davidson(eps,1);
82: EPSDavidsonSetRestart_Davidson(eps,6,0);
83: EPSDavidsonSetInitialSize_Davidson(eps,5);
84: EPSDavidsonSetFix_Davidson(eps,0.01);
85: EPSDavidsonSetBOrth_Davidson(eps,PETSC_TRUE);
86: EPSDavidsonSetConstantCorrectionTolerance_Davidson(eps,PETSC_TRUE);
87: EPSDavidsonSetWindowSizes_Davidson(eps,0,0);
88: return(0);
89: }
93: PetscErrorCode EPSSetUp_Davidson(EPS eps)
94: {
96: EPS_DAVIDSON *data = (EPS_DAVIDSON*)eps->data;
97: dvdDashboard *dvd = &data->ddb;
98: dvdBlackboard b;
99: PetscInt nvecs,nscalars,min_size_V,plusk,bs,initv,i,cX_in_proj,cX_in_impr;
100: Mat A,B;
101: KSP ksp;
102: PetscBool t,ipB,ispositive,dynamic;
103: HarmType_t harm;
104: InitType_t init;
105: PetscReal fix;
106: PetscScalar target;
109: /* Setup EPS options and get the problem specification */
110: EPSDavidsonGetBlockSize_Davidson(eps,&bs);
111: if (bs <= 0) bs = 1;
112: if(eps->ncv) {
113: if (eps->ncv<eps->nev) SETERRQ(((PetscObject)eps)->comm,PETSC_ERR_SUP,"The value of ncv must be at least nev");
114: } else if (eps->mpd) eps->ncv = eps->mpd + eps->nev + bs;
115: else if (eps->nev<500)
116: eps->ncv = PetscMin(eps->n-bs,PetscMax(2*eps->nev,eps->nev+15))+bs;
117: else
118: eps->ncv = PetscMin(eps->n-bs,eps->nev+500)+bs;
119: if (!eps->mpd) eps->mpd = eps->ncv;
120: if (eps->mpd > eps->ncv)
121: SETERRQ(((PetscObject)eps)->comm,PETSC_ERR_SUP,"The mpd has to be less or equal than ncv");
122: if (eps->mpd < 2)
123: SETERRQ(((PetscObject)eps)->comm,PETSC_ERR_SUP,"The mpd has to be greater than 2");
124: if (!eps->max_it) eps->max_it = PetscMax(100*eps->ncv,2*eps->n);
125: if (!eps->which) eps->which = EPS_LARGEST_MAGNITUDE;
126: if (eps->ishermitian && (eps->which==EPS_LARGEST_IMAGINARY || eps->which==EPS_SMALLEST_IMAGINARY))
127: SETERRQ(((PetscObject)eps)->comm,PETSC_ERR_SUP,"Wrong value of eps->which");
128: if (!(eps->nev + bs <= eps->ncv))
129: SETERRQ(((PetscObject)eps)->comm,PETSC_ERR_SUP,"The ncv has to be greater than nev plus blocksize!");
131: EPSDavidsonGetRestart_Davidson(eps,&min_size_V,&plusk);
132: if (!min_size_V) min_size_V = PetscMin(PetscMax(bs,5),eps->mpd/2);
133: if (!(min_size_V+bs <= eps->mpd))
134: SETERRQ(((PetscObject)eps)->comm,PETSC_ERR_SUP,"The value of minv must be less than mpd minus blocksize");
135: EPSDavidsonGetInitialSize_Davidson(eps,&initv);
136: if (eps->mpd < initv)
137: SETERRQ(((PetscObject)eps)->comm,PETSC_ERR_SUP,"The initv has to be less or equal than mpd");
139: /* Davidson solvers do not support left eigenvectors */
140: if (eps->leftvecs) SETERRQ(((PetscObject)eps)->comm,PETSC_ERR_SUP,"Left vectors not supported in this solver");
142: /* Set STPrecond as the default ST */
143: if (!((PetscObject)eps->OP)->type_name) {
144: STSetType(eps->OP,STPRECOND);
145: }
146: STPrecondSetKSPHasMat(eps->OP,PETSC_FALSE);
148: /* Change the default sigma to inf if necessary */
149: if (eps->which == EPS_LARGEST_MAGNITUDE || eps->which == EPS_LARGEST_REAL ||
150: eps->which == EPS_LARGEST_IMAGINARY) {
151: STSetDefaultShift(eps->OP,PETSC_MAX_REAL);
152: }
153:
154: /* Davidson solvers only support STPRECOND */
155: STSetUp(eps->OP);
156: PetscTypeCompare((PetscObject)eps->OP,STPRECOND,&t);
157: if (!t) SETERRQ1(((PetscObject)eps)->comm,PETSC_ERR_SUP,"%s only works with precond spectral transformation",
158: ((PetscObject)eps)->type_name);
160: /* Setup problem specification in dvd */
161: STGetOperators(eps->OP,&A,&B);
162: EPSReset_Davidson(eps);
163: PetscMemzero(dvd,sizeof(dvdDashboard));
164: dvd->A = A; dvd->B = eps->isgeneralized? B : PETSC_NULL;
165: ispositive = eps->ispositive;
166: dvd->sA = DVD_MAT_IMPLICIT |
167: (eps->ishermitian? DVD_MAT_HERMITIAN : 0) |
168: ((ispositive && !eps->isgeneralized) ? DVD_MAT_POS_DEF : 0);
169: /* Asume -eps_hermitian means hermitian-definite in generalized problems */
170: if (!ispositive && !eps->isgeneralized && eps->ishermitian) ispositive = PETSC_TRUE;
171: if (!eps->isgeneralized)
172: dvd->sB = DVD_MAT_IMPLICIT | DVD_MAT_HERMITIAN | DVD_MAT_IDENTITY |
173: DVD_MAT_UNITARY | DVD_MAT_POS_DEF;
174: else
175: dvd->sB = DVD_MAT_IMPLICIT |
176: (eps->ishermitian? DVD_MAT_HERMITIAN : 0) |
177: (ispositive? DVD_MAT_POS_DEF : 0);
178: ipB = (dvd->B && data->ipB && DVD_IS(dvd->sB,DVD_MAT_POS_DEF))?PETSC_TRUE:PETSC_FALSE;
179: data->ipB = ipB;
180: dvd->correctXnorm = ipB;
181: dvd->sEP = ((!eps->isgeneralized || (eps->isgeneralized && ipB))? DVD_EP_STD : 0) |
182: (ispositive? DVD_EP_HERMITIAN : 0);
183: dvd->nev = eps->nev;
184: dvd->which = eps->which;
185: dvd->withTarget = PETSC_TRUE;
186: switch(eps->which) {
187: case EPS_TARGET_MAGNITUDE:
188: case EPS_TARGET_IMAGINARY:
189: dvd->target[0] = target = eps->target; dvd->target[1] = 1.0;
190: break;
192: case EPS_TARGET_REAL:
193: dvd->target[0] = PetscRealPart(target = eps->target); dvd->target[1] = 1.0;
194: break;
196: case EPS_LARGEST_REAL:
197: case EPS_LARGEST_MAGNITUDE:
198: case EPS_LARGEST_IMAGINARY: /* TODO: think about this case */
199: default:
200: dvd->target[0] = 1.0; dvd->target[1] = target = 0.0;
201: break;
202:
203: case EPS_SMALLEST_MAGNITUDE:
204: case EPS_SMALLEST_REAL:
205: case EPS_SMALLEST_IMAGINARY: /* TODO: think about this case */
206: dvd->target[0] = target = 0.0; dvd->target[1] = 1.0;
207: break;
209: case EPS_WHICH_USER:
210: STGetShift(eps->OP,&target);
211: dvd->target[0] = target; dvd->target[1] = 1.0;
212: break;
214: case EPS_ALL:
215: SETERRQ(((PetscObject)eps)->comm,PETSC_ERR_SUP,"Unsupported option: which == EPS_ALL");
216: break;
217: }
218: dvd->tol = eps->tol==PETSC_DEFAULT?SLEPC_DEFAULT_TOL:eps->tol;
219: dvd->eps = eps;
221: /* Setup the extraction technique */
222: if (!eps->extraction) {
223: if (ipB || ispositive) eps->extraction = EPS_RITZ;
224: else {
225: switch(eps->which) {
226: case EPS_TARGET_REAL: case EPS_TARGET_MAGNITUDE: case EPS_TARGET_IMAGINARY:
227: case EPS_SMALLEST_MAGNITUDE: case EPS_SMALLEST_REAL: case EPS_SMALLEST_IMAGINARY:
228: eps->extraction = EPS_HARMONIC;
229: break;
230: case EPS_LARGEST_REAL: case EPS_LARGEST_MAGNITUDE: case EPS_LARGEST_IMAGINARY:
231: eps->extraction = EPS_HARMONIC_LARGEST;
232: break;
233: default:
234: eps->extraction = EPS_RITZ;
235: }
236: }
237: }
238: switch(eps->extraction) {
239: case EPS_RITZ: harm = DVD_HARM_NONE; break;
240: case EPS_HARMONIC: harm = DVD_HARM_RR; break;
241: case EPS_HARMONIC_RELATIVE: harm = DVD_HARM_RRR; break;
242: case EPS_HARMONIC_RIGHT: harm = DVD_HARM_REIGS; break;
243: case EPS_HARMONIC_LARGEST: harm = DVD_HARM_LEIGS; break;
244: default: SETERRQ(((PetscObject)eps)->comm,PETSC_ERR_SUP,"Unsupported extraction type");
245: }
247: /* Setup the type of starting subspace */
248: EPSDavidsonGetKrylovStart_Davidson(eps,&t);
249: init = (!t)? DVD_INITV_CLASSIC : DVD_INITV_KRYLOV;
251: /* Setup the presence of converged vectors in the projected problem and in the projector */
252: EPSDavidsonGetWindowSizes_Davidson(eps,&cX_in_impr,&cX_in_proj);
253: if (min_size_V <= cX_in_proj) {
254: SETERRQ(((PetscObject)eps)->comm,PETSC_ERR_SUP,"minv has to be greater than qwindow");
255: }
256: if (bs > 1 && cX_in_impr > 0) {
257: SETERRQ(((PetscObject)eps)->comm,PETSC_ERR_SUP,"Unsupported option: pwindow > 0 and bs > 1");
258: }
260: /* Setup IP */
261: if (ipB && dvd->B) {
262: IPSetMatrix(eps->ip,dvd->B);
263: } else {
264: IPSetMatrix(eps->ip,PETSC_NULL);
265: }
267: /* Get the fix parameter */
268: EPSDavidsonGetFix_Davidson(eps,&fix);
270: /* Get whether the stopping criterion is used */
271: EPSDavidsonGetConstantCorrectionTolerance_Davidson(eps,&dynamic);
273: /* Orthonormalize the DS */
274: dvd_orthV(eps->ip,PETSC_NULL,0,PETSC_NULL,0,eps->DS,0,
275: PetscAbs(eps->nds),PETSC_NULL,eps->rand);
277: /* Preconfigure dvd */
278: STGetKSP(eps->OP,&ksp);
279: dvd_schm_basic_preconf(dvd,&b,eps->mpd,min_size_V,bs,
280: initv,
281: PetscAbs(eps->nini),
282: plusk,harm,
283: ksp,init,eps->trackall,
284: ipB?DVD_ORTHOV_BOneMV:DVD_ORTHOV_I,cX_in_proj,cX_in_impr);
285:
287: /* Allocate memory */
288: nvecs = b.max_size_auxV + b.own_vecs;
289: nscalars = b.own_scalars + b.max_size_auxS;
290: PetscMalloc(nscalars*sizeof(PetscScalar),&data->wS);
291: VecDuplicateVecs(eps->t,nvecs,&data->wV);
292: data->size_wV = nvecs;
293: b.free_vecs = data->wV;
294: b.free_scalars = data->wS;
295: dvd->auxV = data->wV + b.own_vecs;
296: dvd->auxS = b.free_scalars + b.own_scalars;
297: dvd->size_auxV = b.max_size_auxV;
298: dvd->size_auxS = b.max_size_auxS;
300: eps->errest_left = PETSC_NULL;
301: PetscMalloc(eps->ncv*sizeof(PetscInt),&eps->perm);
302: for(i=0; i<eps->ncv; i++) eps->perm[i] = i;
304: /* Configure dvd for a basic GD */
305: dvd_schm_basic_conf(dvd,&b,eps->mpd,min_size_V,bs,
306: initv,
307: PetscAbs(eps->nini),plusk,
308: eps->ip,harm,dvd->withTarget,
309: target,ksp,
310: fix,init,eps->trackall,
311: ipB?DVD_ORTHOV_BOneMV:DVD_ORTHOV_I,cX_in_proj,cX_in_impr,dynamic);
312:
314: /* Associate the eigenvalues to the EPS */
315: eps->eigr = dvd->real_eigr;
316: eps->eigi = dvd->real_eigi;
317: eps->errest = dvd->real_errest;
318: eps->V = dvd->real_V;
320:
321: return(0);
322: }
326: PetscErrorCode EPSSolve_Davidson(EPS eps)
327: {
328: EPS_DAVIDSON *data = (EPS_DAVIDSON*)eps->data;
329: dvdDashboard *d = &data->ddb;
333: /* Call the starting routines */
334: DVD_FL_CALL(d->startList,d);
336: for(eps->its=0; eps->its < eps->max_it; eps->its++) {
337: /* Initialize V, if it is needed */
338: if (d->size_V == 0) { d->initV(d); }
340: /* Find the best approximated eigenpairs in V, X */
341: d->calcPairs(d);
343: /* Test for convergence */
344: if (eps->nconv >= eps->nev) break;
346: /* Expand the subspace */
347: d->updateV(d);
349: /* Monitor progress */
350: eps->nconv = d->nconv;
351: EPSMonitor(eps,eps->its+1,eps->nconv,eps->eigr,eps->eigi,eps->errest,d->size_V+d->size_cX);
352: }
354: /* Call the ending routines */
355: DVD_FL_CALL(d->endList,d);
357: if (eps->nconv >= eps->nev) eps->reason = EPS_CONVERGED_TOL;
358: else eps->reason = EPS_DIVERGED_ITS;
360: return(0);
361: }
365: PetscErrorCode EPSReset_Davidson(EPS eps)
366: {
367: EPS_DAVIDSON *data = (EPS_DAVIDSON*)eps->data;
368: dvdDashboard *dvd = &data->ddb;
372: /* Call step destructors and destroys the list */
373: DVD_FL_CALL(dvd->destroyList,dvd);
374: DVD_FL_DEL(dvd->destroyList);
375: DVD_FL_DEL(dvd->startList);
376: DVD_FL_DEL(dvd->endList);
378: if (data->size_wV > 0) {
379: VecDestroyVecs(data->size_wV,&data->wV);
380: }
381: PetscFree(data->wS);
382: PetscFree(eps->perm);
383: return(0);
384: }
388: PetscErrorCode EPSView_Davidson(EPS eps,PetscViewer viewer)
389: {
391: PetscBool isascii,opb;
392: PetscInt opi,opi0;
393: const char* name;
396: name = ((PetscObject)eps)->type_name;
397: PetscTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&isascii);
398: if (!isascii) {
399: SETERRQ2(((PetscObject)eps)->comm,1,"Viewer type %s not supported for %s",((PetscObject)viewer)->type_name,name);
400: }
401:
402: EPSDavidsonGetBOrth_Davidson(eps,&opb);
403: EPSDavidsonGetBlockSize_Davidson(eps,&opi);
404: if(!opb) {
405: PetscViewerASCIIPrintf(viewer," Davidson: search subspace is I-orthogonalized\n");
406: } else {
407: PetscViewerASCIIPrintf(viewer," Davidson: search subspace is B-orthogonalized\n");
408: }
409: PetscViewerASCIIPrintf(viewer," Davidson: block size=%D\n",opi);
410: EPSDavidsonGetKrylovStart_Davidson(eps,&opb);
411: if(!opb) {
412: PetscViewerASCIIPrintf(viewer," Davidson: type of the initial subspace: non-Krylov\n");
413: } else {
414: PetscViewerASCIIPrintf(viewer," Davidson: type of the initial subspace: Krylov\n");
415: }
416: EPSDavidsonGetRestart_Davidson(eps,&opi,&opi0);
417: PetscViewerASCIIPrintf(viewer," Davidson: size of the subspace after restarting: %D\n",opi);
418: PetscViewerASCIIPrintf(viewer," Davidson: number of vectors after restarting from the previous iteration: %D\n",opi0);
419: return(0);
420: }
424: PetscErrorCode EPSDavidsonSetKrylovStart_Davidson(EPS eps,PetscBool krylovstart)
425: {
426: EPS_DAVIDSON *data = (EPS_DAVIDSON*)eps->data;
429: data->krylovstart = krylovstart;
430: return(0);
431: }
435: PetscErrorCode EPSDavidsonGetKrylovStart_Davidson(EPS eps,PetscBool *krylovstart)
436: {
437: EPS_DAVIDSON *data = (EPS_DAVIDSON*)eps->data;
440: *krylovstart = data->krylovstart;
441: return(0);
442: }
446: PetscErrorCode EPSDavidsonSetBlockSize_Davidson(EPS eps,PetscInt blocksize)
447: {
448: EPS_DAVIDSON *data = (EPS_DAVIDSON*)eps->data;
451: if(blocksize == PETSC_DEFAULT || blocksize == PETSC_DECIDE) blocksize = 1;
452: if(blocksize <= 0)
453: SETERRQ(((PetscObject)eps)->comm,PETSC_ERR_ARG_OUTOFRANGE,"Invalid blocksize value");
454: data->blocksize = blocksize;
455: return(0);
456: }
460: PetscErrorCode EPSDavidsonGetBlockSize_Davidson(EPS eps,PetscInt *blocksize)
461: {
462: EPS_DAVIDSON *data = (EPS_DAVIDSON*)eps->data;
465: *blocksize = data->blocksize;
466: return(0);
467: }
471: PetscErrorCode EPSDavidsonSetRestart_Davidson(EPS eps,PetscInt minv,PetscInt plusk)
472: {
473: EPS_DAVIDSON *data = (EPS_DAVIDSON*)eps->data;
476: if(minv == PETSC_DEFAULT || minv == PETSC_DECIDE) minv = 5;
477: if(minv <= 0)
478: SETERRQ(((PetscObject)eps)->comm,PETSC_ERR_ARG_OUTOFRANGE,"Invalid minv value");
479: if(plusk == PETSC_DEFAULT || plusk == PETSC_DECIDE) plusk = 5;
480: if(plusk < 0)
481: SETERRQ(((PetscObject)eps)->comm,PETSC_ERR_ARG_OUTOFRANGE,"Invalid plusk value");
482: data->minv = minv;
483: data->plusk = plusk;
484: return(0);
485: }
489: PetscErrorCode EPSDavidsonGetRestart_Davidson(EPS eps,PetscInt *minv,PetscInt *plusk)
490: {
491: EPS_DAVIDSON *data = (EPS_DAVIDSON*)eps->data;
494: *minv = data->minv;
495: *plusk = data->plusk;
496: return(0);
497: }
501: PetscErrorCode EPSDavidsonGetInitialSize_Davidson(EPS eps,PetscInt *initialsize)
502: {
503: EPS_DAVIDSON *data = (EPS_DAVIDSON*)eps->data;
506: *initialsize = data->initialsize;
507: return(0);
508: }
512: PetscErrorCode EPSDavidsonSetInitialSize_Davidson(EPS eps,PetscInt initialsize)
513: {
514: EPS_DAVIDSON *data = (EPS_DAVIDSON*)eps->data;
517: if(initialsize == PETSC_DEFAULT || initialsize == PETSC_DECIDE) initialsize = 5;
518: if(initialsize <= 0)
519: SETERRQ(((PetscObject)eps)->comm,PETSC_ERR_ARG_OUTOFRANGE,"Invalid initial size value");
520: data->initialsize = initialsize;
521: return(0);
522: }
526: PetscErrorCode EPSDavidsonGetFix_Davidson(EPS eps,PetscReal *fix)
527: {
528: EPS_DAVIDSON *data = (EPS_DAVIDSON*)eps->data;
531: *fix = data->fix;
532: return(0);
533: }
537: PetscErrorCode EPSDavidsonSetFix_Davidson(EPS eps,PetscReal fix)
538: {
539: EPS_DAVIDSON *data = (EPS_DAVIDSON*)eps->data;
542: if(fix == PETSC_DEFAULT || fix == PETSC_DECIDE) fix = 0.01;
543: if(fix < 0.0)
544: SETERRQ(((PetscObject)eps)->comm,PETSC_ERR_ARG_OUTOFRANGE,"Invalid fix value");
545: data->fix = fix;
546: return(0);
547: }
551: PetscErrorCode EPSDavidsonSetBOrth_Davidson(EPS eps,PetscBool borth)
552: {
553: EPS_DAVIDSON *data = (EPS_DAVIDSON*)eps->data;
556: data->ipB = borth;
557: return(0);
558: }
562: PetscErrorCode EPSDavidsonGetBOrth_Davidson(EPS eps,PetscBool *borth)
563: {
564: EPS_DAVIDSON *data = (EPS_DAVIDSON*)eps->data;
567: *borth = data->ipB;
568: return(0);
569: }
573: PetscErrorCode EPSDavidsonSetConstantCorrectionTolerance_Davidson(EPS eps,PetscBool constant)
574: {
575: EPS_DAVIDSON *data = (EPS_DAVIDSON*)eps->data;
578: data->dynamic = !constant?PETSC_TRUE:PETSC_FALSE;
579: return(0);
580: }
584: PetscErrorCode EPSDavidsonGetConstantCorrectionTolerance_Davidson(EPS eps,PetscBool *constant)
585: {
586: EPS_DAVIDSON *data = (EPS_DAVIDSON*)eps->data;
589: *constant = !data->dynamic?PETSC_TRUE:PETSC_FALSE;
590: return(0);
591: }
596: PetscErrorCode EPSDavidsonSetWindowSizes_Davidson(EPS eps,PetscInt pwindow,PetscInt qwindow)
597: {
598: EPS_DAVIDSON *data = (EPS_DAVIDSON*)eps->data;
601: if(pwindow == PETSC_DEFAULT || pwindow == PETSC_DECIDE) pwindow = 0;
602: if(pwindow < 0)
603: SETERRQ(((PetscObject)eps)->comm,PETSC_ERR_ARG_OUTOFRANGE,"Invalid pwindow value");
604: if(qwindow == PETSC_DEFAULT || qwindow == PETSC_DECIDE) qwindow = 0;
605: if(qwindow < 0)
606: SETERRQ(((PetscObject)eps)->comm,PETSC_ERR_ARG_OUTOFRANGE,"Invalid qwindow value");
607: data->cX_in_proj = qwindow;
608: data->cX_in_impr = pwindow;
609: return(0);
610: }
614: PetscErrorCode EPSDavidsonGetWindowSizes_Davidson(EPS eps,PetscInt *pwindow,PetscInt *qwindow)
615: {
616: EPS_DAVIDSON *data = (EPS_DAVIDSON*)eps->data;
619: *pwindow = data->cX_in_impr;
620: *qwindow = data->cX_in_proj;
621: return(0);
622: }
627: /*
628: EPSComputeVectors_Davidson - Compute eigenvectors from the vectors
629: provided by the eigensolver. This version is intended for solvers
630: that provide Schur vectors from the QZ decompositon. Given the partial
631: Schur decomposition OP*V=V*T, the following steps are performed:
632: 1) compute eigenvectors of (S,T): S*Z=T*Z*D
633: 2) compute eigenvectors of OP: X=V*Z
634: If left eigenvectors are required then also do Z'*Tl=D*Z', Y=W*Z
635: */
636: PetscErrorCode EPSComputeVectors_Davidson(EPS eps)
637: {
639: EPS_DAVIDSON *data = (EPS_DAVIDSON*)eps->data;
640: dvdDashboard *d = &data->ddb;
641: PetscScalar *pX,*auxS;
642: PetscInt size_auxS;
646: if (d->cS) {
647: /* Compute the eigenvectors associated to (cS, cT) */
648: PetscMalloc(sizeof(PetscScalar)*d->nconv*d->nconv,&pX);
649: size_auxS = 6*d->nconv;
650: PetscMalloc(sizeof(PetscScalar)*size_auxS,&auxS);
651: EPSCleanDenseSchur(d->nconv,0,d->cS,d->ldcS,d->cT,d->ldcT,d->ceigi,pX,d->nconv,PETSC_FALSE);
652: dvd_compute_eigenvectors(d->nconv,d->cS,d->ldcS,d->cT,d->ldcT,
653: pX,d->nconv,PETSC_NULL,0,auxS,
654: size_auxS,PETSC_FALSE);
655:
656: /* pX[i] <- pX[i] / ||pX[i]|| */
657: SlepcDenseNorm(pX,d->nconv,d->nconv,d->nconv,d->ceigi);
658:
659: /* V <- cX * pX */
660: SlepcUpdateVectorsZ(eps->V,0.0,1.0,d->cX,d->size_cX,pX,
661: d->nconv,d->nconv,d->nconv);
662:
663: PetscFree(pX);
664: PetscFree(auxS);
665: }
667: eps->evecsavailable = PETSC_TRUE;
668: return(0);
669: }