1: /*
2: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3: SLEPc - Scalable Library for Eigenvalue Problem Computations
4: Copyright (c) 2002-2021, Universitat Politecnica de Valencia, Spain
6: This file is part of SLEPc.
7: SLEPc is distributed under a 2-clause BSD license (see LICENSE).
8: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
9: */
10: /*
11: PEP routines related to options that can be set via the command-line
12: or procedurally
13: */
15: #include <slepc/private/pepimpl.h> 16: #include <petscdraw.h>
18: /*@C
19: PEPMonitorSetFromOptions - Sets a monitor function and viewer appropriate for the type
20: indicated by the user.
22: Collective on pep
24: Input Parameters:
25: + pep - the polynomial eigensolver context
26: . opt - the command line option for this monitor
27: . name - the monitor type one is seeking
28: . ctx - an optional user context for the monitor, or NULL
29: - trackall - whether this monitor tracks all eigenvalues or not
31: Level: developer
33: .seealso: PEPMonitorSet(), PEPSetTrackAll()
34: @*/
35: PetscErrorCode PEPMonitorSetFromOptions(PEP pep,const char opt[],const char name[],void *ctx,PetscBool trackall) 36: {
37: PetscErrorCode (*mfunc)(PEP,PetscInt,PetscInt,PetscScalar*,PetscScalar*,PetscReal*,PetscInt,void*);
38: PetscErrorCode (*cfunc)(PetscViewer,PetscViewerFormat,void*,PetscViewerAndFormat**);
39: PetscErrorCode (*dfunc)(PetscViewerAndFormat**);
40: PetscViewerAndFormat *vf;
41: PetscViewer viewer;
42: PetscViewerFormat format;
43: PetscViewerType vtype;
44: char key[PETSC_MAX_PATH_LEN];
45: PetscBool flg;
46: PetscErrorCode ierr;
49: PetscOptionsGetViewer(PetscObjectComm((PetscObject)pep),((PetscObject)pep)->options,((PetscObject)pep)->prefix,opt,&viewer,&format,&flg);
50: if (!flg) return(0);
52: PetscViewerGetType(viewer,&vtype);
53: SlepcMonitorMakeKey_Internal(name,vtype,format,key);
54: PetscFunctionListFind(PEPMonitorList,key,&mfunc);
55: PetscFunctionListFind(PEPMonitorCreateList,key,&cfunc);
56: PetscFunctionListFind(PEPMonitorDestroyList,key,&dfunc);
57: if (!cfunc) cfunc = PetscViewerAndFormatCreate_Internal;
58: if (!dfunc) dfunc = PetscViewerAndFormatDestroy;
60: (*cfunc)(viewer,format,ctx,&vf);
61: PetscObjectDereference((PetscObject)viewer);
62: PEPMonitorSet(pep,mfunc,vf,(PetscErrorCode(*)(void **))dfunc);
63: if (trackall) {
64: PEPSetTrackAll(pep,PETSC_TRUE);
65: }
66: return(0);
67: }
69: /*@
70: PEPSetFromOptions - Sets PEP options from the options database.
71: This routine must be called before PEPSetUp() if the user is to be
72: allowed to set the solver type.
74: Collective on pep
76: Input Parameters:
77: . pep - the polynomial eigensolver context
79: Notes:
80: To see all options, run your program with the -help option.
82: Level: beginner
83: @*/
84: PetscErrorCode PEPSetFromOptions(PEP pep) 85: {
86: PetscErrorCode ierr;
87: char type[256];
88: PetscBool set,flg,flg1,flg2,flg3,flg4,flg5;
89: PetscReal r,t,array[2]={0,0};
90: PetscScalar s;
91: PetscInt i,j,k;
92: PEPScale scale;
93: PEPRefine refine;
94: PEPRefineScheme scheme;
98: PEPRegisterAll();
99: PetscObjectOptionsBegin((PetscObject)pep);
100: PetscOptionsFList("-pep_type","Polynomial eigensolver method","PEPSetType",PEPList,(char*)(((PetscObject)pep)->type_name?((PetscObject)pep)->type_name:PEPTOAR),type,sizeof(type),&flg);
101: if (flg) {
102: PEPSetType(pep,type);
103: } else if (!((PetscObject)pep)->type_name) {
104: PEPSetType(pep,PEPTOAR);
105: }
107: PetscOptionsBoolGroupBegin("-pep_general","General polynomial eigenvalue problem","PEPSetProblemType",&flg);
108: if (flg) { PEPSetProblemType(pep,PEP_GENERAL); }
109: PetscOptionsBoolGroup("-pep_hermitian","Hermitian polynomial eigenvalue problem","PEPSetProblemType",&flg);
110: if (flg) { PEPSetProblemType(pep,PEP_HERMITIAN); }
111: PetscOptionsBoolGroup("-pep_hyperbolic","Hyperbolic polynomial eigenvalue problem","PEPSetProblemType",&flg);
112: if (flg) { PEPSetProblemType(pep,PEP_HYPERBOLIC); }
113: PetscOptionsBoolGroupEnd("-pep_gyroscopic","Gyroscopic polynomial eigenvalue problem","PEPSetProblemType",&flg);
114: if (flg) { PEPSetProblemType(pep,PEP_GYROSCOPIC); }
116: scale = pep->scale;
117: PetscOptionsEnum("-pep_scale","Scaling strategy","PEPSetScale",PEPScaleTypes,(PetscEnum)scale,(PetscEnum*)&scale,&flg1);
118: r = pep->sfactor;
119: PetscOptionsReal("-pep_scale_factor","Scale factor","PEPSetScale",pep->sfactor,&r,&flg2);
120: if (!flg2 && r==1.0) r = PETSC_DEFAULT;
121: j = pep->sits;
122: PetscOptionsInt("-pep_scale_its","Number of iterations in diagonal scaling","PEPSetScale",pep->sits,&j,&flg3);
123: t = pep->slambda;
124: PetscOptionsReal("-pep_scale_lambda","Estimate of eigenvalue (modulus) for diagonal scaling","PEPSetScale",pep->slambda,&t,&flg4);
125: if (flg1 || flg2 || flg3 || flg4) { PEPSetScale(pep,scale,r,NULL,NULL,j,t); }
127: PetscOptionsEnum("-pep_extract","Extraction method","PEPSetExtract",PEPExtractTypes,(PetscEnum)pep->extract,(PetscEnum*)&pep->extract,NULL);
129: refine = pep->refine;
130: PetscOptionsEnum("-pep_refine","Iterative refinement method","PEPSetRefine",PEPRefineTypes,(PetscEnum)refine,(PetscEnum*)&refine,&flg1);
131: i = pep->npart;
132: PetscOptionsInt("-pep_refine_partitions","Number of partitions of the communicator for iterative refinement","PEPSetRefine",pep->npart,&i,&flg2);
133: r = pep->rtol;
134: PetscOptionsReal("-pep_refine_tol","Tolerance for iterative refinement","PEPSetRefine",pep->rtol==PETSC_DEFAULT?SLEPC_DEFAULT_TOL/1000:pep->rtol,&r,&flg3);
135: j = pep->rits;
136: PetscOptionsInt("-pep_refine_its","Maximum number of iterations for iterative refinement","PEPSetRefine",pep->rits,&j,&flg4);
137: scheme = pep->scheme;
138: PetscOptionsEnum("-pep_refine_scheme","Scheme used for linear systems within iterative refinement","PEPSetRefine",PEPRefineSchemes,(PetscEnum)scheme,(PetscEnum*)&scheme,&flg5);
139: if (flg1 || flg2 || flg3 || flg4 || flg5) { PEPSetRefine(pep,refine,i,r,j,scheme); }
141: i = pep->max_it;
142: PetscOptionsInt("-pep_max_it","Maximum number of iterations","PEPSetTolerances",pep->max_it,&i,&flg1);
143: r = pep->tol;
144: PetscOptionsReal("-pep_tol","Tolerance","PEPSetTolerances",pep->tol==PETSC_DEFAULT?SLEPC_DEFAULT_TOL:pep->tol,&r,&flg2);
145: if (flg1 || flg2) { PEPSetTolerances(pep,r,i); }
147: PetscOptionsBoolGroupBegin("-pep_conv_rel","Relative error convergence test","PEPSetConvergenceTest",&flg);
148: if (flg) { PEPSetConvergenceTest(pep,PEP_CONV_REL); }
149: PetscOptionsBoolGroup("-pep_conv_norm","Convergence test relative to the matrix norms","PEPSetConvergenceTest",&flg);
150: if (flg) { PEPSetConvergenceTest(pep,PEP_CONV_NORM); }
151: PetscOptionsBoolGroup("-pep_conv_abs","Absolute error convergence test","PEPSetConvergenceTest",&flg);
152: if (flg) { PEPSetConvergenceTest(pep,PEP_CONV_ABS); }
153: PetscOptionsBoolGroupEnd("-pep_conv_user","User-defined convergence test","PEPSetConvergenceTest",&flg);
154: if (flg) { PEPSetConvergenceTest(pep,PEP_CONV_USER); }
156: PetscOptionsBoolGroupBegin("-pep_stop_basic","Stop iteration if all eigenvalues converged or max_it reached","PEPSetStoppingTest",&flg);
157: if (flg) { PEPSetStoppingTest(pep,PEP_STOP_BASIC); }
158: PetscOptionsBoolGroupEnd("-pep_stop_user","User-defined stopping test","PEPSetStoppingTest",&flg);
159: if (flg) { PEPSetStoppingTest(pep,PEP_STOP_USER); }
161: i = pep->nev;
162: PetscOptionsInt("-pep_nev","Number of eigenvalues to compute","PEPSetDimensions",pep->nev,&i,&flg1);
163: j = pep->ncv;
164: PetscOptionsInt("-pep_ncv","Number of basis vectors","PEPSetDimensions",pep->ncv,&j,&flg2);
165: k = pep->mpd;
166: PetscOptionsInt("-pep_mpd","Maximum dimension of projected problem","PEPSetDimensions",pep->mpd,&k,&flg3);
167: if (flg1 || flg2 || flg3) { PEPSetDimensions(pep,i,j,k); }
169: PetscOptionsEnum("-pep_basis","Polynomial basis","PEPSetBasis",PEPBasisTypes,(PetscEnum)pep->basis,(PetscEnum*)&pep->basis,NULL);
171: PetscOptionsBoolGroupBegin("-pep_largest_magnitude","Compute largest eigenvalues in magnitude","PEPSetWhichEigenpairs",&flg);
172: if (flg) { PEPSetWhichEigenpairs(pep,PEP_LARGEST_MAGNITUDE); }
173: PetscOptionsBoolGroup("-pep_smallest_magnitude","Compute smallest eigenvalues in magnitude","PEPSetWhichEigenpairs",&flg);
174: if (flg) { PEPSetWhichEigenpairs(pep,PEP_SMALLEST_MAGNITUDE); }
175: PetscOptionsBoolGroup("-pep_largest_real","Compute eigenvalues with largest real parts","PEPSetWhichEigenpairs",&flg);
176: if (flg) { PEPSetWhichEigenpairs(pep,PEP_LARGEST_REAL); }
177: PetscOptionsBoolGroup("-pep_smallest_real","Compute eigenvalues with smallest real parts","PEPSetWhichEigenpairs",&flg);
178: if (flg) { PEPSetWhichEigenpairs(pep,PEP_SMALLEST_REAL); }
179: PetscOptionsBoolGroup("-pep_largest_imaginary","Compute eigenvalues with largest imaginary parts","PEPSetWhichEigenpairs",&flg);
180: if (flg) { PEPSetWhichEigenpairs(pep,PEP_LARGEST_IMAGINARY); }
181: PetscOptionsBoolGroup("-pep_smallest_imaginary","Compute eigenvalues with smallest imaginary parts","PEPSetWhichEigenpairs",&flg);
182: if (flg) { PEPSetWhichEigenpairs(pep,PEP_SMALLEST_IMAGINARY); }
183: PetscOptionsBoolGroup("-pep_target_magnitude","Compute eigenvalues closest to target","PEPSetWhichEigenpairs",&flg);
184: if (flg) { PEPSetWhichEigenpairs(pep,PEP_TARGET_MAGNITUDE); }
185: PetscOptionsBoolGroup("-pep_target_real","Compute eigenvalues with real parts closest to target","PEPSetWhichEigenpairs",&flg);
186: if (flg) { PEPSetWhichEigenpairs(pep,PEP_TARGET_REAL); }
187: PetscOptionsBoolGroup("-pep_target_imaginary","Compute eigenvalues with imaginary parts closest to target","PEPSetWhichEigenpairs",&flg);
188: if (flg) { PEPSetWhichEigenpairs(pep,PEP_TARGET_IMAGINARY); }
189: PetscOptionsBoolGroupEnd("-pep_all","Compute all eigenvalues in an interval or a region","PEPSetWhichEigenpairs",&flg);
190: if (flg) { PEPSetWhichEigenpairs(pep,PEP_ALL); }
192: PetscOptionsScalar("-pep_target","Value of the target","PEPSetTarget",pep->target,&s,&flg);
193: if (flg) {
194: if (pep->which!=PEP_TARGET_REAL && pep->which!=PEP_TARGET_IMAGINARY) {
195: PEPSetWhichEigenpairs(pep,PEP_TARGET_MAGNITUDE);
196: }
197: PEPSetTarget(pep,s);
198: }
200: k = 2;
201: PetscOptionsRealArray("-pep_interval","Computational interval (two real values separated with a comma without spaces)","PEPSetInterval",array,&k,&flg);
202: if (flg) {
203: if (k<2) SETERRQ(PetscObjectComm((PetscObject)pep),PETSC_ERR_ARG_SIZ,"Must pass two values in -pep_interval (comma-separated without spaces)");
204: PEPSetWhichEigenpairs(pep,PEP_ALL);
205: PEPSetInterval(pep,array[0],array[1]);
206: }
208: /* -----------------------------------------------------------------------*/
209: /*
210: Cancels all monitors hardwired into code before call to PEPSetFromOptions()
211: */
212: PetscOptionsBool("-pep_monitor_cancel","Remove any hardwired monitor routines","PEPMonitorCancel",PETSC_FALSE,&flg,&set);
213: if (set && flg) { PEPMonitorCancel(pep); }
214: PEPMonitorSetFromOptions(pep,"-pep_monitor","first_approximation",NULL,PETSC_FALSE);
215: PEPMonitorSetFromOptions(pep,"-pep_monitor_all","all_approximations",NULL,PETSC_TRUE);
216: PEPMonitorSetFromOptions(pep,"-pep_monitor_conv","convergence_history",NULL,PETSC_FALSE);
218: /* -----------------------------------------------------------------------*/
219: PetscOptionsName("-pep_view","Print detailed information on solver used","PEPView",NULL);
220: PetscOptionsName("-pep_view_vectors","View computed eigenvectors","PEPVectorsView",NULL);
221: PetscOptionsName("-pep_view_values","View computed eigenvalues","PEPValuesView",NULL);
222: PetscOptionsName("-pep_converged_reason","Print reason for convergence, and number of iterations","PEPConvergedReasonView",NULL);
223: PetscOptionsName("-pep_error_absolute","Print absolute errors of each eigenpair","PEPErrorView",NULL);
224: PetscOptionsName("-pep_error_relative","Print relative errors of each eigenpair","PEPErrorView",NULL);
225: PetscOptionsName("-pep_error_backward","Print backward errors of each eigenpair","PEPErrorView",NULL);
227: if (pep->ops->setfromoptions) {
228: (*pep->ops->setfromoptions)(PetscOptionsObject,pep);
229: }
230: PetscObjectProcessOptionsHandlers(PetscOptionsObject,(PetscObject)pep);
231: PetscOptionsEnd();
233: if (!pep->V) { PEPGetBV(pep,&pep->V); }
234: BVSetFromOptions(pep->V);
235: if (!pep->rg) { PEPGetRG(pep,&pep->rg); }
236: RGSetFromOptions(pep->rg);
237: if (!pep->ds) { PEPGetDS(pep,&pep->ds); }
238: DSSetFromOptions(pep->ds);
239: if (!pep->st) { PEPGetST(pep,&pep->st); }
240: PEPSetDefaultST(pep);
241: STSetFromOptions(pep->st);
242: if (!pep->refineksp) { PEPRefineGetKSP(pep,&pep->refineksp); }
243: KSPSetFromOptions(pep->refineksp);
244: return(0);
245: }
247: /*@C
248: PEPGetTolerances - Gets the tolerance and maximum iteration count used
249: by the PEP convergence tests.
251: Not Collective
253: Input Parameter:
254: . pep - the polynomial eigensolver context
256: Output Parameters:
257: + tol - the convergence tolerance
258: - maxits - maximum number of iterations
260: Notes:
261: The user can specify NULL for any parameter that is not needed.
263: Level: intermediate
265: .seealso: PEPSetTolerances()
266: @*/
267: PetscErrorCode PEPGetTolerances(PEP pep,PetscReal *tol,PetscInt *maxits)268: {
271: if (tol) *tol = pep->tol;
272: if (maxits) *maxits = pep->max_it;
273: return(0);
274: }
276: /*@
277: PEPSetTolerances - Sets the tolerance and maximum iteration count used
278: by the PEP convergence tests.
280: Logically Collective on pep
282: Input Parameters:
283: + pep - the polynomial eigensolver context
284: . tol - the convergence tolerance
285: - maxits - maximum number of iterations to use
287: Options Database Keys:
288: + -pep_tol <tol> - Sets the convergence tolerance
289: - -pep_max_it <maxits> - Sets the maximum number of iterations allowed
291: Notes:
292: Use PETSC_DEFAULT for either argument to assign a reasonably good value.
294: Level: intermediate
296: .seealso: PEPGetTolerances()
297: @*/
298: PetscErrorCode PEPSetTolerances(PEP pep,PetscReal tol,PetscInt maxits)299: {
304: if (tol == PETSC_DEFAULT) {
305: pep->tol = PETSC_DEFAULT;
306: pep->state = PEP_STATE_INITIAL;
307: } else {
308: if (tol <= 0.0) SETERRQ(PetscObjectComm((PetscObject)pep),PETSC_ERR_ARG_OUTOFRANGE,"Illegal value of tol. Must be > 0");
309: pep->tol = tol;
310: }
311: if (maxits == PETSC_DEFAULT || maxits == PETSC_DECIDE) {
312: pep->max_it = PETSC_DEFAULT;
313: pep->state = PEP_STATE_INITIAL;
314: } else {
315: if (maxits <= 0) SETERRQ(PetscObjectComm((PetscObject)pep),PETSC_ERR_ARG_OUTOFRANGE,"Illegal value of maxits. Must be > 0");
316: pep->max_it = maxits;
317: }
318: return(0);
319: }
321: /*@C
322: PEPGetDimensions - Gets the number of eigenvalues to compute
323: and the dimension of the subspace.
325: Not Collective
327: Input Parameter:
328: . pep - the polynomial eigensolver context
330: Output Parameters:
331: + nev - number of eigenvalues to compute
332: . ncv - the maximum dimension of the subspace to be used by the solver
333: - mpd - the maximum dimension allowed for the projected problem
335: Notes:
336: The user can specify NULL for any parameter that is not needed.
338: Level: intermediate
340: .seealso: PEPSetDimensions()
341: @*/
342: PetscErrorCode PEPGetDimensions(PEP pep,PetscInt *nev,PetscInt *ncv,PetscInt *mpd)343: {
346: if (nev) *nev = pep->nev;
347: if (ncv) *ncv = pep->ncv;
348: if (mpd) *mpd = pep->mpd;
349: return(0);
350: }
352: /*@
353: PEPSetDimensions - Sets the number of eigenvalues to compute
354: and the dimension of the subspace.
356: Logically Collective on pep
358: Input Parameters:
359: + pep - the polynomial eigensolver context
360: . nev - number of eigenvalues to compute
361: . ncv - the maximum dimension of the subspace to be used by the solver
362: - mpd - the maximum dimension allowed for the projected problem
364: Options Database Keys:
365: + -pep_nev <nev> - Sets the number of eigenvalues
366: . -pep_ncv <ncv> - Sets the dimension of the subspace
367: - -pep_mpd <mpd> - Sets the maximum projected dimension
369: Notes:
370: Use PETSC_DEFAULT for ncv and mpd to assign a reasonably good value, which is
371: dependent on the solution method.
373: The parameters ncv and mpd are intimately related, so that the user is advised
374: to set one of them at most. Normal usage is that
375: (a) in cases where nev is small, the user sets ncv (a reasonable default is 2*nev); and
376: (b) in cases where nev is large, the user sets mpd.
378: The value of ncv should always be between nev and (nev+mpd), typically
379: ncv=nev+mpd. If nev is not too large, mpd=nev is a reasonable choice, otherwise
380: a smaller value should be used.
382: When computing all eigenvalues in an interval, see PEPSetInterval(), these
383: parameters lose relevance, and tuning must be done with PEPSTOARSetDimensions().
385: Level: intermediate
387: .seealso: PEPGetDimensions(), PEPSetInterval(), PEPSTOARSetDimensions()
388: @*/
389: PetscErrorCode PEPSetDimensions(PEP pep,PetscInt nev,PetscInt ncv,PetscInt mpd)390: {
396: if (nev<1) SETERRQ(PetscObjectComm((PetscObject)pep),PETSC_ERR_ARG_OUTOFRANGE,"Illegal value of nev. Must be > 0");
397: pep->nev = nev;
398: if (ncv == PETSC_DECIDE || ncv == PETSC_DEFAULT) {
399: pep->ncv = PETSC_DEFAULT;
400: } else {
401: if (ncv<1) SETERRQ(PetscObjectComm((PetscObject)pep),PETSC_ERR_ARG_OUTOFRANGE,"Illegal value of ncv. Must be > 0");
402: pep->ncv = ncv;
403: }
404: if (mpd == PETSC_DECIDE || mpd == PETSC_DEFAULT) {
405: pep->mpd = PETSC_DEFAULT;
406: } else {
407: if (mpd<1) SETERRQ(PetscObjectComm((PetscObject)pep),PETSC_ERR_ARG_OUTOFRANGE,"Illegal value of mpd. Must be > 0");
408: pep->mpd = mpd;
409: }
410: pep->state = PEP_STATE_INITIAL;
411: return(0);
412: }
414: /*@
415: PEPSetWhichEigenpairs - Specifies which portion of the spectrum is
416: to be sought.
418: Logically Collective on pep
420: Input Parameters:
421: + pep - eigensolver context obtained from PEPCreate()
422: - which - the portion of the spectrum to be sought
424: Possible values:
425: The parameter 'which' can have one of these values
427: + PEP_LARGEST_MAGNITUDE - largest eigenvalues in magnitude (default)
428: . PEP_SMALLEST_MAGNITUDE - smallest eigenvalues in magnitude
429: . PEP_LARGEST_REAL - largest real parts
430: . PEP_SMALLEST_REAL - smallest real parts
431: . PEP_LARGEST_IMAGINARY - largest imaginary parts
432: . PEP_SMALLEST_IMAGINARY - smallest imaginary parts
433: . PEP_TARGET_MAGNITUDE - eigenvalues closest to the target (in magnitude)
434: . PEP_TARGET_REAL - eigenvalues with real part closest to target
435: . PEP_TARGET_IMAGINARY - eigenvalues with imaginary part closest to target
436: . PEP_ALL - all eigenvalues contained in a given interval
437: - PEP_WHICH_USER - user defined ordering set with PEPSetEigenvalueComparison()
439: Options Database Keys:
440: + -pep_largest_magnitude - Sets largest eigenvalues in magnitude
441: . -pep_smallest_magnitude - Sets smallest eigenvalues in magnitude
442: . -pep_largest_real - Sets largest real parts
443: . -pep_smallest_real - Sets smallest real parts
444: . -pep_largest_imaginary - Sets largest imaginary parts
445: . -pep_smallest_imaginary - Sets smallest imaginary parts
446: . -pep_target_magnitude - Sets eigenvalues closest to target
447: . -pep_target_real - Sets real parts closest to target
448: . -pep_target_imaginary - Sets imaginary parts closest to target
449: - -pep_all - Sets all eigenvalues in an interval
451: Notes:
452: Not all eigensolvers implemented in PEP account for all the possible values
453: stated above. If SLEPc is compiled for real numbers PEP_LARGEST_IMAGINARY454: and PEP_SMALLEST_IMAGINARY use the absolute value of the imaginary part
455: for eigenvalue selection.
457: The target is a scalar value provided with PEPSetTarget().
459: The criterion PEP_TARGET_IMAGINARY is available only in case PETSc and
460: SLEPc have been built with complex scalars.
462: PEP_ALL is intended for use in combination with an interval (see
463: PEPSetInterval()), when all eigenvalues within the interval are requested.
464: In that case, the number of eigenvalues is unknown, so the nev parameter
465: has a different sense, see PEPSetDimensions().
467: Level: intermediate
469: .seealso: PEPGetWhichEigenpairs(), PEPSetTarget(), PEPSetInterval(),
470: PEPSetDimensions(), PEPSetEigenvalueComparison(), PEPWhich471: @*/
472: PetscErrorCode PEPSetWhichEigenpairs(PEP pep,PEPWhich which)473: {
477: switch (which) {
478: case PEP_LARGEST_MAGNITUDE:
479: case PEP_SMALLEST_MAGNITUDE:
480: case PEP_LARGEST_REAL:
481: case PEP_SMALLEST_REAL:
482: case PEP_LARGEST_IMAGINARY:
483: case PEP_SMALLEST_IMAGINARY:
484: case PEP_TARGET_MAGNITUDE:
485: case PEP_TARGET_REAL:
486: #if defined(PETSC_USE_COMPLEX)
487: case PEP_TARGET_IMAGINARY:
488: #endif
489: case PEP_ALL:
490: case PEP_WHICH_USER:
491: if (pep->which != which) {
492: pep->state = PEP_STATE_INITIAL;
493: pep->which = which;
494: }
495: break;
496: #if !defined(PETSC_USE_COMPLEX)
497: case PEP_TARGET_IMAGINARY:
498: SETERRQ(PetscObjectComm((PetscObject)pep),PETSC_ERR_SUP,"PEP_TARGET_IMAGINARY can be used only with complex scalars");
499: #endif
500: default:501: SETERRQ(PetscObjectComm((PetscObject)pep),PETSC_ERR_ARG_OUTOFRANGE,"Invalid 'which' value");
502: }
503: return(0);
504: }
506: /*@
507: PEPGetWhichEigenpairs - Returns which portion of the spectrum is to be
508: sought.
510: Not Collective
512: Input Parameter:
513: . pep - eigensolver context obtained from PEPCreate()
515: Output Parameter:
516: . which - the portion of the spectrum to be sought
518: Notes:
519: See PEPSetWhichEigenpairs() for possible values of 'which'.
521: Level: intermediate
523: .seealso: PEPSetWhichEigenpairs(), PEPWhich524: @*/
525: PetscErrorCode PEPGetWhichEigenpairs(PEP pep,PEPWhich *which)526: {
530: *which = pep->which;
531: return(0);
532: }
534: /*@C
535: PEPSetEigenvalueComparison - Specifies the eigenvalue comparison function
536: when PEPSetWhichEigenpairs() is set to PEP_WHICH_USER.
538: Logically Collective on pep
540: Input Parameters:
541: + pep - eigensolver context obtained from PEPCreate()
542: . func - a pointer to the comparison function
543: - ctx - a context pointer (the last parameter to the comparison function)
545: Calling Sequence of func:
546: $ func(PetscScalar ar,PetscScalar ai,PetscScalar br,PetscScalar bi,PetscInt *res,void *ctx)
548: + ar - real part of the 1st eigenvalue
549: . ai - imaginary part of the 1st eigenvalue
550: . br - real part of the 2nd eigenvalue
551: . bi - imaginary part of the 2nd eigenvalue
552: . res - result of comparison
553: - ctx - optional context, as set by PEPSetEigenvalueComparison()
555: Note:
556: The returning parameter 'res' can be
557: + negative - if the 1st eigenvalue is preferred to the 2st one
558: . zero - if both eigenvalues are equally preferred
559: - positive - if the 2st eigenvalue is preferred to the 1st one
561: Level: advanced
563: .seealso: PEPSetWhichEigenpairs(), PEPWhich564: @*/
565: PetscErrorCode PEPSetEigenvalueComparison(PEP pep,PetscErrorCode (*func)(PetscScalar,PetscScalar,PetscScalar,PetscScalar,PetscInt*,void*),void* ctx)566: {
569: pep->sc->comparison = func;
570: pep->sc->comparisonctx = ctx;
571: pep->which = PEP_WHICH_USER;
572: return(0);
573: }
575: /*@
576: PEPSetProblemType - Specifies the type of the polynomial eigenvalue problem.
578: Logically Collective on pep
580: Input Parameters:
581: + pep - the polynomial eigensolver context
582: - type - a known type of polynomial eigenvalue problem
584: Options Database Keys:
585: + -pep_general - general problem with no particular structure
586: . -pep_hermitian - problem whose coefficient matrices are Hermitian
587: . -pep_hyperbolic - Hermitian problem that satisfies the definition of hyperbolic
588: - -pep_gyroscopic - problem with Hamiltonian structure
590: Notes:
591: Allowed values for the problem type are: general (PEP_GENERAL), Hermitian
592: (PEP_HERMITIAN), hyperbolic (PEP_HYPERBOLIC), and gyroscopic (PEP_GYROSCOPIC).
594: This function is used to instruct SLEPc to exploit certain structure in
595: the polynomial eigenproblem. By default, no particular structure is assumed.
597: If the problem matrices are Hermitian (symmetric in the real case) or
598: Hermitian/skew-Hermitian then the solver can exploit this fact to perform
599: less operations or provide better stability. Hyperbolic problems are a
600: particular case of Hermitian problems, some solvers may treat them simply as
601: Hermitian.
603: Level: intermediate
605: .seealso: PEPSetOperators(), PEPSetType(), PEPGetProblemType(), PEPProblemType606: @*/
607: PetscErrorCode PEPSetProblemType(PEP pep,PEPProblemType type)608: {
612: if (type!=PEP_GENERAL && type!=PEP_HERMITIAN && type!=PEP_HYPERBOLIC && type!=PEP_GYROSCOPIC) SETERRQ(PetscObjectComm((PetscObject)pep),PETSC_ERR_ARG_WRONG,"Unknown eigenvalue problem type");
613: if (type != pep->problem_type) {
614: pep->problem_type = type;
615: pep->state = PEP_STATE_INITIAL;
616: }
617: return(0);
618: }
620: /*@
621: PEPGetProblemType - Gets the problem type from the PEP object.
623: Not Collective
625: Input Parameter:
626: . pep - the polynomial eigensolver context
628: Output Parameter:
629: . type - the problem type
631: Level: intermediate
633: .seealso: PEPSetProblemType(), PEPProblemType634: @*/
635: PetscErrorCode PEPGetProblemType(PEP pep,PEPProblemType *type)636: {
640: *type = pep->problem_type;
641: return(0);
642: }
644: /*@
645: PEPSetBasis - Specifies the type of polynomial basis used to describe the
646: polynomial eigenvalue problem.
648: Logically Collective on pep
650: Input Parameters:
651: + pep - the polynomial eigensolver context
652: - basis - the type of polynomial basis
654: Options Database Key:
655: . -pep_basis <basis> - Select the basis type
657: Notes:
658: By default, the coefficient matrices passed via PEPSetOperators() are
659: expressed in the monomial basis, i.e.
660: P(lambda) = A_0 + lambda*A_1 + lambda^2*A_2 + ... + lambda^d*A_d.
661: Other polynomial bases may have better numerical behaviour, but the user
662: must then pass the coefficient matrices accordingly.
664: Level: intermediate
666: .seealso: PEPSetOperators(), PEPGetBasis(), PEPBasis667: @*/
668: PetscErrorCode PEPSetBasis(PEP pep,PEPBasis basis)669: {
673: pep->basis = basis;
674: return(0);
675: }
677: /*@
678: PEPGetBasis - Gets the type of polynomial basis from the PEP object.
680: Not Collective
682: Input Parameter:
683: . pep - the polynomial eigensolver context
685: Output Parameter:
686: . basis - the polynomial basis
688: Level: intermediate
690: .seealso: PEPSetBasis(), PEPBasis691: @*/
692: PetscErrorCode PEPGetBasis(PEP pep,PEPBasis *basis)693: {
697: *basis = pep->basis;
698: return(0);
699: }
701: /*@
702: PEPSetTrackAll - Specifies if the solver must compute the residual of all
703: approximate eigenpairs or not.
705: Logically Collective on pep
707: Input Parameters:
708: + pep - the eigensolver context
709: - trackall - whether compute all residuals or not
711: Notes:
712: If the user sets trackall=PETSC_TRUE then the solver explicitly computes
713: the residual for each eigenpair approximation. Computing the residual is
714: usually an expensive operation and solvers commonly compute the associated
715: residual to the first unconverged eigenpair.
717: The option '-pep_monitor_all' automatically activates this option.
719: Level: developer
721: .seealso: PEPGetTrackAll()
722: @*/
723: PetscErrorCode PEPSetTrackAll(PEP pep,PetscBool trackall)724: {
728: pep->trackall = trackall;
729: return(0);
730: }
732: /*@
733: PEPGetTrackAll - Returns the flag indicating whether all residual norms must
734: be computed or not.
736: Not Collective
738: Input Parameter:
739: . pep - the eigensolver context
741: Output Parameter:
742: . trackall - the returned flag
744: Level: developer
746: .seealso: PEPSetTrackAll()
747: @*/
748: PetscErrorCode PEPGetTrackAll(PEP pep,PetscBool *trackall)749: {
753: *trackall = pep->trackall;
754: return(0);
755: }
757: /*@C
758: PEPSetConvergenceTestFunction - Sets a function to compute the error estimate
759: used in the convergence test.
761: Logically Collective on pep
763: Input Parameters:
764: + pep - eigensolver context obtained from PEPCreate()
765: . func - a pointer to the convergence test function
766: . ctx - context for private data for the convergence routine (may be null)
767: - destroy - a routine for destroying the context (may be null)
769: Calling Sequence of func:
770: $ func(PEP pep,PetscScalar eigr,PetscScalar eigi,PetscReal res,PetscReal *errest,void *ctx)
772: + pep - eigensolver context obtained from PEPCreate()
773: . eigr - real part of the eigenvalue
774: . eigi - imaginary part of the eigenvalue
775: . res - residual norm associated to the eigenpair
776: . errest - (output) computed error estimate
777: - ctx - optional context, as set by PEPSetConvergenceTestFunction()
779: Note:
780: If the error estimate returned by the convergence test function is less than
781: the tolerance, then the eigenvalue is accepted as converged.
783: Level: advanced
785: .seealso: PEPSetConvergenceTest(), PEPSetTolerances()
786: @*/
787: PetscErrorCode PEPSetConvergenceTestFunction(PEP pep,PetscErrorCode (*func)(PEP,PetscScalar,PetscScalar,PetscReal,PetscReal*,void*),void* ctx,PetscErrorCode (*destroy)(void*))788: {
793: if (pep->convergeddestroy) {
794: (*pep->convergeddestroy)(pep->convergedctx);
795: }
796: pep->convergeduser = func;
797: pep->convergeddestroy = destroy;
798: pep->convergedctx = ctx;
799: if (func == PEPConvergedRelative) pep->conv = PEP_CONV_REL;
800: else if (func == PEPConvergedNorm) pep->conv = PEP_CONV_NORM;
801: else if (func == PEPConvergedAbsolute) pep->conv = PEP_CONV_ABS;
802: else {
803: pep->conv = PEP_CONV_USER;
804: pep->converged = pep->convergeduser;
805: }
806: return(0);
807: }
809: /*@
810: PEPSetConvergenceTest - Specifies how to compute the error estimate
811: used in the convergence test.
813: Logically Collective on pep
815: Input Parameters:
816: + pep - eigensolver context obtained from PEPCreate()
817: - conv - the type of convergence test
819: Options Database Keys:
820: + -pep_conv_abs - Sets the absolute convergence test
821: . -pep_conv_rel - Sets the convergence test relative to the eigenvalue
822: . -pep_conv_norm - Sets the convergence test relative to the matrix norms
823: - -pep_conv_user - Selects the user-defined convergence test
825: Note:
826: The parameter 'conv' can have one of these values
827: + PEP_CONV_ABS - absolute error ||r||
828: . PEP_CONV_REL - error relative to the eigenvalue l, ||r||/|l|
829: . PEP_CONV_NORM - error relative matrix norms, ||r||/sum_i(l^i*||A_i||)
830: - PEP_CONV_USER - function set by PEPSetConvergenceTestFunction()
832: Level: intermediate
834: .seealso: PEPGetConvergenceTest(), PEPSetConvergenceTestFunction(), PEPSetStoppingTest(), PEPConv835: @*/
836: PetscErrorCode PEPSetConvergenceTest(PEP pep,PEPConv conv)837: {
841: switch (conv) {
842: case PEP_CONV_ABS: pep->converged = PEPConvergedAbsolute; break;
843: case PEP_CONV_REL: pep->converged = PEPConvergedRelative; break;
844: case PEP_CONV_NORM: pep->converged = PEPConvergedNorm; break;
845: case PEP_CONV_USER:
846: if (!pep->convergeduser) SETERRQ(PetscObjectComm((PetscObject)pep),PETSC_ERR_ORDER,"Must call PEPSetConvergenceTestFunction() first");
847: pep->converged = pep->convergeduser;
848: break;
849: default:850: SETERRQ(PetscObjectComm((PetscObject)pep),PETSC_ERR_ARG_OUTOFRANGE,"Invalid 'conv' value");
851: }
852: pep->conv = conv;
853: return(0);
854: }
856: /*@
857: PEPGetConvergenceTest - Gets the method used to compute the error estimate
858: used in the convergence test.
860: Not Collective
862: Input Parameters:
863: . pep - eigensolver context obtained from PEPCreate()
865: Output Parameters:
866: . conv - the type of convergence test
868: Level: intermediate
870: .seealso: PEPSetConvergenceTest(), PEPConv871: @*/
872: PetscErrorCode PEPGetConvergenceTest(PEP pep,PEPConv *conv)873: {
877: *conv = pep->conv;
878: return(0);
879: }
881: /*@C
882: PEPSetStoppingTestFunction - Sets a function to decide when to stop the outer
883: iteration of the eigensolver.
885: Logically Collective on pep
887: Input Parameters:
888: + pep - eigensolver context obtained from PEPCreate()
889: . func - pointer to the stopping test function
890: . ctx - context for private data for the stopping routine (may be null)
891: - destroy - a routine for destroying the context (may be null)
893: Calling Sequence of func:
894: $ func(PEP pep,PetscInt its,PetscInt max_it,PetscInt nconv,PetscInt nev,PEPConvergedReason *reason,void *ctx)
896: + pep - eigensolver context obtained from PEPCreate()
897: . its - current number of iterations
898: . max_it - maximum number of iterations
899: . nconv - number of currently converged eigenpairs
900: . nev - number of requested eigenpairs
901: . reason - (output) result of the stopping test
902: - ctx - optional context, as set by PEPSetStoppingTestFunction()
904: Note:
905: Normal usage is to first call the default routine PEPStoppingBasic() and then
906: set reason to PEP_CONVERGED_USER if some user-defined conditions have been
907: met. To let the eigensolver continue iterating, the result must be left as
908: PEP_CONVERGED_ITERATING.
910: Level: advanced
912: .seealso: PEPSetStoppingTest(), PEPStoppingBasic()
913: @*/
914: PetscErrorCode PEPSetStoppingTestFunction(PEP pep,PetscErrorCode (*func)(PEP,PetscInt,PetscInt,PetscInt,PetscInt,PEPConvergedReason*,void*),void* ctx,PetscErrorCode (*destroy)(void*))915: {
920: if (pep->stoppingdestroy) {
921: (*pep->stoppingdestroy)(pep->stoppingctx);
922: }
923: pep->stoppinguser = func;
924: pep->stoppingdestroy = destroy;
925: pep->stoppingctx = ctx;
926: if (func == PEPStoppingBasic) pep->stop = PEP_STOP_BASIC;
927: else {
928: pep->stop = PEP_STOP_USER;
929: pep->stopping = pep->stoppinguser;
930: }
931: return(0);
932: }
934: /*@
935: PEPSetStoppingTest - Specifies how to decide the termination of the outer
936: loop of the eigensolver.
938: Logically Collective on pep
940: Input Parameters:
941: + pep - eigensolver context obtained from PEPCreate()
942: - stop - the type of stopping test
944: Options Database Keys:
945: + -pep_stop_basic - Sets the default stopping test
946: - -pep_stop_user - Selects the user-defined stopping test
948: Note:
949: The parameter 'stop' can have one of these values
950: + PEP_STOP_BASIC - default stopping test
951: - PEP_STOP_USER - function set by PEPSetStoppingTestFunction()
953: Level: advanced
955: .seealso: PEPGetStoppingTest(), PEPSetStoppingTestFunction(), PEPSetConvergenceTest(), PEPStop956: @*/
957: PetscErrorCode PEPSetStoppingTest(PEP pep,PEPStop stop)958: {
962: switch (stop) {
963: case PEP_STOP_BASIC: pep->stopping = PEPStoppingBasic; break;
964: case PEP_STOP_USER:
965: if (!pep->stoppinguser) SETERRQ(PetscObjectComm((PetscObject)pep),PETSC_ERR_ORDER,"Must call PEPSetStoppingTestFunction() first");
966: pep->stopping = pep->stoppinguser;
967: break;
968: default:969: SETERRQ(PetscObjectComm((PetscObject)pep),PETSC_ERR_ARG_OUTOFRANGE,"Invalid 'stop' value");
970: }
971: pep->stop = stop;
972: return(0);
973: }
975: /*@
976: PEPGetStoppingTest - Gets the method used to decide the termination of the outer
977: loop of the eigensolver.
979: Not Collective
981: Input Parameters:
982: . pep - eigensolver context obtained from PEPCreate()
984: Output Parameters:
985: . stop - the type of stopping test
987: Level: advanced
989: .seealso: PEPSetStoppingTest(), PEPStop990: @*/
991: PetscErrorCode PEPGetStoppingTest(PEP pep,PEPStop *stop)992: {
996: *stop = pep->stop;
997: return(0);
998: }
1000: /*@
1001: PEPSetScale - Specifies the scaling strategy to be used.
1003: Logically Collective on pep
1005: Input Parameters:
1006: + pep - the eigensolver context
1007: . scale - scaling strategy
1008: . alpha - the scaling factor used in the scalar strategy
1009: . Dl - the left diagonal matrix of the diagonal scaling algorithm
1010: . Dr - the right diagonal matrix of the diagonal scaling algorithm
1011: . its - number of iterations of the diagonal scaling algorithm
1012: - lambda - approximation to wanted eigenvalues (modulus)
1014: Options Database Keys:
1015: + -pep_scale <type> - scaling type, one of <none,scalar,diagonal,both>
1016: . -pep_scale_factor <alpha> - the scaling factor
1017: . -pep_scale_its <its> - number of iterations
1018: - -pep_scale_lambda <lambda> - approximation to eigenvalues
1020: Notes:
1021: There are two non-exclusive scaling strategies: scalar and diagonal.
1023: In the scalar strategy, scaling is applied to the eigenvalue, that is,
1024: mu = lambda/alpha is the new eigenvalue and all matrices are scaled
1025: accordingly. After solving the scaled problem, the original lambda is
1026: recovered. Parameter 'alpha' must be positive. Use PETSC_DEFAULT to let
1027: the solver compute a reasonable scaling factor.
1029: In the diagonal strategy, the solver works implicitly with matrix Dl*A*Dr,
1030: where Dl and Dr are appropriate diagonal matrices. This improves the accuracy
1031: of the computed results in some cases. The user may provide the Dr and Dl
1032: matrices represented as Vec objects storing diagonal elements. If not
1033: provided, these matrices are computed internally. This option requires
1034: that the polynomial coefficient matrices are of MATAIJ type.
1035: The parameter 'its' is the number of iterations performed by the method.
1036: Parameter 'lambda' must be positive. Use PETSC_DEFAULT or set lambda = 1.0 if
1037: no information about eigenvalues is available.
1039: Level: intermediate
1041: .seealso: PEPGetScale()
1042: @*/
1043: PetscErrorCode PEPSetScale(PEP pep,PEPScale scale,PetscReal alpha,Vec Dl,Vec Dr,PetscInt its,PetscReal lambda)1044: {
1050: pep->scale = scale;
1051: if (scale==PEP_SCALE_SCALAR || scale==PEP_SCALE_BOTH) {
1053: if (alpha == PETSC_DEFAULT || alpha == PETSC_DECIDE) {
1054: pep->sfactor = 0.0;
1055: pep->sfactor_set = PETSC_FALSE;
1056: } else {
1057: if (alpha<=0.0) SETERRQ(PetscObjectComm((PetscObject)pep),PETSC_ERR_ARG_OUTOFRANGE,"Illegal value of alpha. Must be > 0");
1058: pep->sfactor = alpha;
1059: pep->sfactor_set = PETSC_TRUE;
1060: }
1061: }
1062: if (scale==PEP_SCALE_DIAGONAL || scale==PEP_SCALE_BOTH) {
1063: if (Dl) {
1066: PetscObjectReference((PetscObject)Dl);
1067: VecDestroy(&pep->Dl);
1068: pep->Dl = Dl;
1069: }
1070: if (Dr) {
1073: PetscObjectReference((PetscObject)Dr);
1074: VecDestroy(&pep->Dr);
1075: pep->Dr = Dr;
1076: }
1079: if (its==PETSC_DECIDE || its==PETSC_DEFAULT) pep->sits = 5;
1080: else pep->sits = its;
1081: if (lambda==PETSC_DECIDE || lambda==PETSC_DEFAULT) pep->slambda = 1.0;
1082: else if (lambda<=0.0) SETERRQ(PetscObjectComm((PetscObject)pep),PETSC_ERR_ARG_OUTOFRANGE,"Illegal value of lambda. Must be > 0");
1083: else pep->slambda = lambda;
1084: }
1085: pep->state = PEP_STATE_INITIAL;
1086: return(0);
1087: }
1089: /*@C
1090: PEPGetScale - Gets the scaling strategy used by the PEP object, and the
1091: associated parameters.
1093: Not Collectiv, but vectors are shared by all processors that share the PEP1095: Input Parameter:
1096: . pep - the eigensolver context
1098: Output Parameters:
1099: + scale - scaling strategy
1100: . alpha - the scaling factor used in the scalar strategy
1101: . Dl - the left diagonal matrix of the diagonal scaling algorithm
1102: . Dr - the right diagonal matrix of the diagonal scaling algorithm
1103: . its - number of iterations of the diagonal scaling algorithm
1104: - lambda - approximation to wanted eigenvalues (modulus)
1106: Level: intermediate
1108: Note:
1109: The user can specify NULL for any parameter that is not needed.
1111: If Dl or Dr were not set by the user, then the ones computed internally are
1112: returned (or a null pointer if called before PEPSetUp).
1114: .seealso: PEPSetScale(), PEPSetUp()
1115: @*/
1116: PetscErrorCode PEPGetScale(PEP pep,PEPScale *scale,PetscReal *alpha,Vec *Dl,Vec *Dr,PetscInt *its,PetscReal *lambda)1117: {
1120: if (scale) *scale = pep->scale;
1121: if (alpha) *alpha = pep->sfactor;
1122: if (Dl) *Dl = pep->Dl;
1123: if (Dr) *Dr = pep->Dr;
1124: if (its) *its = pep->sits;
1125: if (lambda) *lambda = pep->slambda;
1126: return(0);
1127: }
1129: /*@
1130: PEPSetExtract - Specifies the extraction strategy to be used.
1132: Logically Collective on pep
1134: Input Parameters:
1135: + pep - the eigensolver context
1136: - extract - extraction strategy
1138: Options Database Keys:
1139: . -pep_extract <type> - extraction type, one of <none,norm,residual,structured>
1141: Level: intermediate
1143: .seealso: PEPGetExtract()
1144: @*/
1145: PetscErrorCode PEPSetExtract(PEP pep,PEPExtract extract)1146: {
1150: pep->extract = extract;
1151: return(0);
1152: }
1154: /*@
1155: PEPGetExtract - Gets the extraction strategy used by the PEP object.
1157: Not Collective
1159: Input Parameter:
1160: . pep - the eigensolver context
1162: Output Parameter:
1163: . extract - extraction strategy
1165: Level: intermediate
1167: .seealso: PEPSetExtract(), PEPExtract1168: @*/
1169: PetscErrorCode PEPGetExtract(PEP pep,PEPExtract *extract)1170: {
1174: *extract = pep->extract;
1175: return(0);
1176: }
1178: /*@
1179: PEPSetRefine - Specifies the refinement type (and options) to be used
1180: after the solve.
1182: Logically Collective on pep
1184: Input Parameters:
1185: + pep - the polynomial eigensolver context
1186: . refine - refinement type
1187: . npart - number of partitions of the communicator
1188: . tol - the convergence tolerance
1189: . its - maximum number of refinement iterations
1190: - scheme - which scheme to be used for solving the involved linear systems
1192: Options Database Keys:
1193: + -pep_refine <type> - refinement type, one of <none,simple,multiple>
1194: . -pep_refine_partitions <n> - the number of partitions
1195: . -pep_refine_tol <tol> - the tolerance
1196: . -pep_refine_its <its> - number of iterations
1197: - -pep_refine_scheme - to set the scheme for the linear solves
1199: Notes:
1200: By default, iterative refinement is disabled, since it may be very
1201: costly. There are two possible refinement strategies: simple and multiple.
1202: The simple approach performs iterative refinement on each of the
1203: converged eigenpairs individually, whereas the multiple strategy works
1204: with the invariant pair as a whole, refining all eigenpairs simultaneously.
1205: The latter may be required for the case of multiple eigenvalues.
1207: In some cases, especially when using direct solvers within the
1208: iterative refinement method, it may be helpful for improved scalability
1209: to split the communicator in several partitions. The npart parameter
1210: indicates how many partitions to use (defaults to 1).
1212: The tol and its parameters specify the stopping criterion. In the simple
1213: method, refinement continues until the residual of each eigenpair is
1214: below the tolerance (tol defaults to the PEP tol, but may be set to a
1215: different value). In contrast, the multiple method simply performs its
1216: refinement iterations (just one by default).
1218: The scheme argument is used to change the way in which linear systems are
1219: solved. Possible choices are: explicit, mixed block elimination (MBE),
1220: and Schur complement.
1222: Level: intermediate
1224: .seealso: PEPGetRefine()
1225: @*/
1226: PetscErrorCode PEPSetRefine(PEP pep,PEPRefine refine,PetscInt npart,PetscReal tol,PetscInt its,PEPRefineScheme scheme)1227: {
1229: PetscMPIInt size;
1238: pep->refine = refine;
1239: if (refine) { /* process parameters only if not REFINE_NONE */
1240: if (npart!=pep->npart) {
1241: PetscSubcommDestroy(&pep->refinesubc);
1242: KSPDestroy(&pep->refineksp);
1243: }
1244: if (npart == PETSC_DEFAULT || npart == PETSC_DECIDE) {
1245: pep->npart = 1;
1246: } else {
1247: MPI_Comm_size(PetscObjectComm((PetscObject)pep),&size);CHKERRMPI(ierr);
1248: if (npart<1 || npart>size) SETERRQ(PetscObjectComm((PetscObject)pep),PETSC_ERR_ARG_OUTOFRANGE,"Illegal value of npart");
1249: pep->npart = npart;
1250: }
1251: if (tol == PETSC_DEFAULT || tol == PETSC_DECIDE) {
1252: pep->rtol = PETSC_DEFAULT;
1253: } else {
1254: if (tol<=0.0) SETERRQ(PetscObjectComm((PetscObject)pep),PETSC_ERR_ARG_OUTOFRANGE,"Illegal value of tol. Must be > 0");
1255: pep->rtol = tol;
1256: }
1257: if (its==PETSC_DECIDE || its==PETSC_DEFAULT) {
1258: pep->rits = PETSC_DEFAULT;
1259: } else {
1260: if (its<0) SETERRQ(PetscObjectComm((PetscObject)pep),PETSC_ERR_ARG_OUTOFRANGE,"Illegal value of its. Must be >= 0");
1261: pep->rits = its;
1262: }
1263: pep->scheme = scheme;
1264: }
1265: pep->state = PEP_STATE_INITIAL;
1266: return(0);
1267: }
1269: /*@C
1270: PEPGetRefine - Gets the refinement strategy used by the PEP object, and the
1271: associated parameters.
1273: Not Collective
1275: Input Parameter:
1276: . pep - the polynomial eigensolver context
1278: Output Parameters:
1279: + refine - refinement type
1280: . npart - number of partitions of the communicator
1281: . tol - the convergence tolerance
1282: . its - maximum number of refinement iterations
1283: - scheme - the scheme used for solving linear systems
1285: Level: intermediate
1287: Note:
1288: The user can specify NULL for any parameter that is not needed.
1290: .seealso: PEPSetRefine()
1291: @*/
1292: PetscErrorCode PEPGetRefine(PEP pep,PEPRefine *refine,PetscInt *npart,PetscReal *tol,PetscInt *its,PEPRefineScheme *scheme)1293: {
1296: if (refine) *refine = pep->refine;
1297: if (npart) *npart = pep->npart;
1298: if (tol) *tol = pep->rtol;
1299: if (its) *its = pep->rits;
1300: if (scheme) *scheme = pep->scheme;
1301: return(0);
1302: }
1304: /*@C
1305: PEPSetOptionsPrefix - Sets the prefix used for searching for all
1306: PEP options in the database.
1308: Logically Collective on pep
1310: Input Parameters:
1311: + pep - the polynomial eigensolver context
1312: - prefix - the prefix string to prepend to all PEP option requests
1314: Notes:
1315: A hyphen (-) must NOT be given at the beginning of the prefix name.
1316: The first character of all runtime options is AUTOMATICALLY the
1317: hyphen.
1319: For example, to distinguish between the runtime options for two
1320: different PEP contexts, one could call
1321: .vb
1322: PEPSetOptionsPrefix(pep1,"qeig1_")
1323: PEPSetOptionsPrefix(pep2,"qeig2_")
1324: .ve
1326: Level: advanced
1328: .seealso: PEPAppendOptionsPrefix(), PEPGetOptionsPrefix()
1329: @*/
1330: PetscErrorCode PEPSetOptionsPrefix(PEP pep,const char *prefix)1331: {
1336: if (!pep->st) { PEPGetST(pep,&pep->st); }
1337: STSetOptionsPrefix(pep->st,prefix);
1338: if (!pep->V) { PEPGetBV(pep,&pep->V); }
1339: BVSetOptionsPrefix(pep->V,prefix);
1340: if (!pep->ds) { PEPGetDS(pep,&pep->ds); }
1341: DSSetOptionsPrefix(pep->ds,prefix);
1342: if (!pep->rg) { PEPGetRG(pep,&pep->rg); }
1343: RGSetOptionsPrefix(pep->rg,prefix);
1344: PetscObjectSetOptionsPrefix((PetscObject)pep,prefix);
1345: return(0);
1346: }
1348: /*@C
1349: PEPAppendOptionsPrefix - Appends to the prefix used for searching for all
1350: PEP options in the database.
1352: Logically Collective on pep
1354: Input Parameters:
1355: + pep - the polynomial eigensolver context
1356: - prefix - the prefix string to prepend to all PEP option requests
1358: Notes:
1359: A hyphen (-) must NOT be given at the beginning of the prefix name.
1360: The first character of all runtime options is AUTOMATICALLY the hyphen.
1362: Level: advanced
1364: .seealso: PEPSetOptionsPrefix(), PEPGetOptionsPrefix()
1365: @*/
1366: PetscErrorCode PEPAppendOptionsPrefix(PEP pep,const char *prefix)1367: {
1372: if (!pep->st) { PEPGetST(pep,&pep->st); }
1373: STAppendOptionsPrefix(pep->st,prefix);
1374: if (!pep->V) { PEPGetBV(pep,&pep->V); }
1375: BVAppendOptionsPrefix(pep->V,prefix);
1376: if (!pep->ds) { PEPGetDS(pep,&pep->ds); }
1377: DSAppendOptionsPrefix(pep->ds,prefix);
1378: if (!pep->rg) { PEPGetRG(pep,&pep->rg); }
1379: RGAppendOptionsPrefix(pep->rg,prefix);
1380: PetscObjectAppendOptionsPrefix((PetscObject)pep,prefix);
1381: return(0);
1382: }
1384: /*@C
1385: PEPGetOptionsPrefix - Gets the prefix used for searching for all
1386: PEP options in the database.
1388: Not Collective
1390: Input Parameters:
1391: . pep - the polynomial eigensolver context
1393: Output Parameters:
1394: . prefix - pointer to the prefix string used is returned
1396: Note:
1397: On the Fortran side, the user should pass in a string 'prefix' of
1398: sufficient length to hold the prefix.
1400: Level: advanced
1402: .seealso: PEPSetOptionsPrefix(), PEPAppendOptionsPrefix()
1403: @*/
1404: PetscErrorCode PEPGetOptionsPrefix(PEP pep,const char *prefix[])1405: {
1411: PetscObjectGetOptionsPrefix((PetscObject)pep,prefix);
1412: return(0);
1413: }