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",SlepcDefaultTol(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 or region
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 or region
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: and also for computing all eigenvalues in a region with the CISS solver.
465: In both cases, the number of eigenvalues is unknown, so the nev parameter
466: has a different sense, see PEPSetDimensions().
468: Level: intermediate
470: .seealso: PEPGetWhichEigenpairs(), PEPSetTarget(), PEPSetInterval(),
471: PEPSetDimensions(), PEPSetEigenvalueComparison(), PEPWhich472: @*/
473: PetscErrorCode PEPSetWhichEigenpairs(PEP pep,PEPWhich which)474: {
478: switch (which) {
479: case PEP_LARGEST_MAGNITUDE:
480: case PEP_SMALLEST_MAGNITUDE:
481: case PEP_LARGEST_REAL:
482: case PEP_SMALLEST_REAL:
483: case PEP_LARGEST_IMAGINARY:
484: case PEP_SMALLEST_IMAGINARY:
485: case PEP_TARGET_MAGNITUDE:
486: case PEP_TARGET_REAL:
487: #if defined(PETSC_USE_COMPLEX)
488: case PEP_TARGET_IMAGINARY:
489: #endif
490: case PEP_ALL:
491: case PEP_WHICH_USER:
492: if (pep->which != which) {
493: pep->state = PEP_STATE_INITIAL;
494: pep->which = which;
495: }
496: break;
497: #if !defined(PETSC_USE_COMPLEX)
498: case PEP_TARGET_IMAGINARY:
499: SETERRQ(PetscObjectComm((PetscObject)pep),PETSC_ERR_SUP,"PEP_TARGET_IMAGINARY can be used only with complex scalars");
500: #endif
501: default:502: SETERRQ(PetscObjectComm((PetscObject)pep),PETSC_ERR_ARG_OUTOFRANGE,"Invalid 'which' value");
503: }
504: return(0);
505: }
507: /*@
508: PEPGetWhichEigenpairs - Returns which portion of the spectrum is to be
509: sought.
511: Not Collective
513: Input Parameter:
514: . pep - eigensolver context obtained from PEPCreate()
516: Output Parameter:
517: . which - the portion of the spectrum to be sought
519: Notes:
520: See PEPSetWhichEigenpairs() for possible values of 'which'.
522: Level: intermediate
524: .seealso: PEPSetWhichEigenpairs(), PEPWhich525: @*/
526: PetscErrorCode PEPGetWhichEigenpairs(PEP pep,PEPWhich *which)527: {
531: *which = pep->which;
532: return(0);
533: }
535: /*@C
536: PEPSetEigenvalueComparison - Specifies the eigenvalue comparison function
537: when PEPSetWhichEigenpairs() is set to PEP_WHICH_USER.
539: Logically Collective on pep
541: Input Parameters:
542: + pep - eigensolver context obtained from PEPCreate()
543: . func - a pointer to the comparison function
544: - ctx - a context pointer (the last parameter to the comparison function)
546: Calling Sequence of func:
547: $ func(PetscScalar ar,PetscScalar ai,PetscScalar br,PetscScalar bi,PetscInt *res,void *ctx)
549: + ar - real part of the 1st eigenvalue
550: . ai - imaginary part of the 1st eigenvalue
551: . br - real part of the 2nd eigenvalue
552: . bi - imaginary part of the 2nd eigenvalue
553: . res - result of comparison
554: - ctx - optional context, as set by PEPSetEigenvalueComparison()
556: Note:
557: The returning parameter 'res' can be
558: + negative - if the 1st eigenvalue is preferred to the 2st one
559: . zero - if both eigenvalues are equally preferred
560: - positive - if the 2st eigenvalue is preferred to the 1st one
562: Level: advanced
564: .seealso: PEPSetWhichEigenpairs(), PEPWhich565: @*/
566: PetscErrorCode PEPSetEigenvalueComparison(PEP pep,PetscErrorCode (*func)(PetscScalar,PetscScalar,PetscScalar,PetscScalar,PetscInt*,void*),void* ctx)567: {
570: pep->sc->comparison = func;
571: pep->sc->comparisonctx = ctx;
572: pep->which = PEP_WHICH_USER;
573: return(0);
574: }
576: /*@
577: PEPSetProblemType - Specifies the type of the polynomial eigenvalue problem.
579: Logically Collective on pep
581: Input Parameters:
582: + pep - the polynomial eigensolver context
583: - type - a known type of polynomial eigenvalue problem
585: Options Database Keys:
586: + -pep_general - general problem with no particular structure
587: . -pep_hermitian - problem whose coefficient matrices are Hermitian
588: . -pep_hyperbolic - Hermitian problem that satisfies the definition of hyperbolic
589: - -pep_gyroscopic - problem with Hamiltonian structure
591: Notes:
592: Allowed values for the problem type are: general (PEP_GENERAL), Hermitian
593: (PEP_HERMITIAN), hyperbolic (PEP_HYPERBOLIC), and gyroscopic (PEP_GYROSCOPIC).
595: This function is used to instruct SLEPc to exploit certain structure in
596: the polynomial eigenproblem. By default, no particular structure is assumed.
598: If the problem matrices are Hermitian (symmetric in the real case) or
599: Hermitian/skew-Hermitian then the solver can exploit this fact to perform
600: less operations or provide better stability. Hyperbolic problems are a
601: particular case of Hermitian problems, some solvers may treat them simply as
602: Hermitian.
604: Level: intermediate
606: .seealso: PEPSetOperators(), PEPSetType(), PEPGetProblemType(), PEPProblemType607: @*/
608: PetscErrorCode PEPSetProblemType(PEP pep,PEPProblemType type)609: {
613: 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");
614: if (type != pep->problem_type) {
615: pep->problem_type = type;
616: pep->state = PEP_STATE_INITIAL;
617: }
618: return(0);
619: }
621: /*@
622: PEPGetProblemType - Gets the problem type from the PEP object.
624: Not Collective
626: Input Parameter:
627: . pep - the polynomial eigensolver context
629: Output Parameter:
630: . type - the problem type
632: Level: intermediate
634: .seealso: PEPSetProblemType(), PEPProblemType635: @*/
636: PetscErrorCode PEPGetProblemType(PEP pep,PEPProblemType *type)637: {
641: *type = pep->problem_type;
642: return(0);
643: }
645: /*@
646: PEPSetBasis - Specifies the type of polynomial basis used to describe the
647: polynomial eigenvalue problem.
649: Logically Collective on pep
651: Input Parameters:
652: + pep - the polynomial eigensolver context
653: - basis - the type of polynomial basis
655: Options Database Key:
656: . -pep_basis <basis> - Select the basis type
658: Notes:
659: By default, the coefficient matrices passed via PEPSetOperators() are
660: expressed in the monomial basis, i.e.
661: P(lambda) = A_0 + lambda*A_1 + lambda^2*A_2 + ... + lambda^d*A_d.
662: Other polynomial bases may have better numerical behaviour, but the user
663: must then pass the coefficient matrices accordingly.
665: Level: intermediate
667: .seealso: PEPSetOperators(), PEPGetBasis(), PEPBasis668: @*/
669: PetscErrorCode PEPSetBasis(PEP pep,PEPBasis basis)670: {
674: pep->basis = basis;
675: return(0);
676: }
678: /*@
679: PEPGetBasis - Gets the type of polynomial basis from the PEP object.
681: Not Collective
683: Input Parameter:
684: . pep - the polynomial eigensolver context
686: Output Parameter:
687: . basis - the polynomial basis
689: Level: intermediate
691: .seealso: PEPSetBasis(), PEPBasis692: @*/
693: PetscErrorCode PEPGetBasis(PEP pep,PEPBasis *basis)694: {
698: *basis = pep->basis;
699: return(0);
700: }
702: /*@
703: PEPSetTrackAll - Specifies if the solver must compute the residual of all
704: approximate eigenpairs or not.
706: Logically Collective on pep
708: Input Parameters:
709: + pep - the eigensolver context
710: - trackall - whether compute all residuals or not
712: Notes:
713: If the user sets trackall=PETSC_TRUE then the solver explicitly computes
714: the residual for each eigenpair approximation. Computing the residual is
715: usually an expensive operation and solvers commonly compute the associated
716: residual to the first unconverged eigenpair.
718: The option '-pep_monitor_all' automatically activates this option.
720: Level: developer
722: .seealso: PEPGetTrackAll()
723: @*/
724: PetscErrorCode PEPSetTrackAll(PEP pep,PetscBool trackall)725: {
729: pep->trackall = trackall;
730: return(0);
731: }
733: /*@
734: PEPGetTrackAll - Returns the flag indicating whether all residual norms must
735: be computed or not.
737: Not Collective
739: Input Parameter:
740: . pep - the eigensolver context
742: Output Parameter:
743: . trackall - the returned flag
745: Level: developer
747: .seealso: PEPSetTrackAll()
748: @*/
749: PetscErrorCode PEPGetTrackAll(PEP pep,PetscBool *trackall)750: {
754: *trackall = pep->trackall;
755: return(0);
756: }
758: /*@C
759: PEPSetConvergenceTestFunction - Sets a function to compute the error estimate
760: used in the convergence test.
762: Logically Collective on pep
764: Input Parameters:
765: + pep - eigensolver context obtained from PEPCreate()
766: . func - a pointer to the convergence test function
767: . ctx - context for private data for the convergence routine (may be null)
768: - destroy - a routine for destroying the context (may be null)
770: Calling Sequence of func:
771: $ func(PEP pep,PetscScalar eigr,PetscScalar eigi,PetscReal res,PetscReal *errest,void *ctx)
773: + pep - eigensolver context obtained from PEPCreate()
774: . eigr - real part of the eigenvalue
775: . eigi - imaginary part of the eigenvalue
776: . res - residual norm associated to the eigenpair
777: . errest - (output) computed error estimate
778: - ctx - optional context, as set by PEPSetConvergenceTestFunction()
780: Note:
781: If the error estimate returned by the convergence test function is less than
782: the tolerance, then the eigenvalue is accepted as converged.
784: Level: advanced
786: .seealso: PEPSetConvergenceTest(), PEPSetTolerances()
787: @*/
788: PetscErrorCode PEPSetConvergenceTestFunction(PEP pep,PetscErrorCode (*func)(PEP,PetscScalar,PetscScalar,PetscReal,PetscReal*,void*),void* ctx,PetscErrorCode (*destroy)(void*))789: {
794: if (pep->convergeddestroy) {
795: (*pep->convergeddestroy)(pep->convergedctx);
796: }
797: pep->convergeduser = func;
798: pep->convergeddestroy = destroy;
799: pep->convergedctx = ctx;
800: if (func == PEPConvergedRelative) pep->conv = PEP_CONV_REL;
801: else if (func == PEPConvergedNorm) pep->conv = PEP_CONV_NORM;
802: else if (func == PEPConvergedAbsolute) pep->conv = PEP_CONV_ABS;
803: else {
804: pep->conv = PEP_CONV_USER;
805: pep->converged = pep->convergeduser;
806: }
807: return(0);
808: }
810: /*@
811: PEPSetConvergenceTest - Specifies how to compute the error estimate
812: used in the convergence test.
814: Logically Collective on pep
816: Input Parameters:
817: + pep - eigensolver context obtained from PEPCreate()
818: - conv - the type of convergence test
820: Options Database Keys:
821: + -pep_conv_abs - Sets the absolute convergence test
822: . -pep_conv_rel - Sets the convergence test relative to the eigenvalue
823: . -pep_conv_norm - Sets the convergence test relative to the matrix norms
824: - -pep_conv_user - Selects the user-defined convergence test
826: Note:
827: The parameter 'conv' can have one of these values
828: + PEP_CONV_ABS - absolute error ||r||
829: . PEP_CONV_REL - error relative to the eigenvalue l, ||r||/|l|
830: . PEP_CONV_NORM - error relative matrix norms, ||r||/sum_i(l^i*||A_i||)
831: - PEP_CONV_USER - function set by PEPSetConvergenceTestFunction()
833: Level: intermediate
835: .seealso: PEPGetConvergenceTest(), PEPSetConvergenceTestFunction(), PEPSetStoppingTest(), PEPConv836: @*/
837: PetscErrorCode PEPSetConvergenceTest(PEP pep,PEPConv conv)838: {
842: switch (conv) {
843: case PEP_CONV_ABS: pep->converged = PEPConvergedAbsolute; break;
844: case PEP_CONV_REL: pep->converged = PEPConvergedRelative; break;
845: case PEP_CONV_NORM: pep->converged = PEPConvergedNorm; break;
846: case PEP_CONV_USER:
847: if (!pep->convergeduser) SETERRQ(PetscObjectComm((PetscObject)pep),PETSC_ERR_ORDER,"Must call PEPSetConvergenceTestFunction() first");
848: pep->converged = pep->convergeduser;
849: break;
850: default:851: SETERRQ(PetscObjectComm((PetscObject)pep),PETSC_ERR_ARG_OUTOFRANGE,"Invalid 'conv' value");
852: }
853: pep->conv = conv;
854: return(0);
855: }
857: /*@
858: PEPGetConvergenceTest - Gets the method used to compute the error estimate
859: used in the convergence test.
861: Not Collective
863: Input Parameters:
864: . pep - eigensolver context obtained from PEPCreate()
866: Output Parameters:
867: . conv - the type of convergence test
869: Level: intermediate
871: .seealso: PEPSetConvergenceTest(), PEPConv872: @*/
873: PetscErrorCode PEPGetConvergenceTest(PEP pep,PEPConv *conv)874: {
878: *conv = pep->conv;
879: return(0);
880: }
882: /*@C
883: PEPSetStoppingTestFunction - Sets a function to decide when to stop the outer
884: iteration of the eigensolver.
886: Logically Collective on pep
888: Input Parameters:
889: + pep - eigensolver context obtained from PEPCreate()
890: . func - pointer to the stopping test function
891: . ctx - context for private data for the stopping routine (may be null)
892: - destroy - a routine for destroying the context (may be null)
894: Calling Sequence of func:
895: $ func(PEP pep,PetscInt its,PetscInt max_it,PetscInt nconv,PetscInt nev,PEPConvergedReason *reason,void *ctx)
897: + pep - eigensolver context obtained from PEPCreate()
898: . its - current number of iterations
899: . max_it - maximum number of iterations
900: . nconv - number of currently converged eigenpairs
901: . nev - number of requested eigenpairs
902: . reason - (output) result of the stopping test
903: - ctx - optional context, as set by PEPSetStoppingTestFunction()
905: Note:
906: Normal usage is to first call the default routine PEPStoppingBasic() and then
907: set reason to PEP_CONVERGED_USER if some user-defined conditions have been
908: met. To let the eigensolver continue iterating, the result must be left as
909: PEP_CONVERGED_ITERATING.
911: Level: advanced
913: .seealso: PEPSetStoppingTest(), PEPStoppingBasic()
914: @*/
915: PetscErrorCode PEPSetStoppingTestFunction(PEP pep,PetscErrorCode (*func)(PEP,PetscInt,PetscInt,PetscInt,PetscInt,PEPConvergedReason*,void*),void* ctx,PetscErrorCode (*destroy)(void*))916: {
921: if (pep->stoppingdestroy) {
922: (*pep->stoppingdestroy)(pep->stoppingctx);
923: }
924: pep->stoppinguser = func;
925: pep->stoppingdestroy = destroy;
926: pep->stoppingctx = ctx;
927: if (func == PEPStoppingBasic) pep->stop = PEP_STOP_BASIC;
928: else {
929: pep->stop = PEP_STOP_USER;
930: pep->stopping = pep->stoppinguser;
931: }
932: return(0);
933: }
935: /*@
936: PEPSetStoppingTest - Specifies how to decide the termination of the outer
937: loop of the eigensolver.
939: Logically Collective on pep
941: Input Parameters:
942: + pep - eigensolver context obtained from PEPCreate()
943: - stop - the type of stopping test
945: Options Database Keys:
946: + -pep_stop_basic - Sets the default stopping test
947: - -pep_stop_user - Selects the user-defined stopping test
949: Note:
950: The parameter 'stop' can have one of these values
951: + PEP_STOP_BASIC - default stopping test
952: - PEP_STOP_USER - function set by PEPSetStoppingTestFunction()
954: Level: advanced
956: .seealso: PEPGetStoppingTest(), PEPSetStoppingTestFunction(), PEPSetConvergenceTest(), PEPStop957: @*/
958: PetscErrorCode PEPSetStoppingTest(PEP pep,PEPStop stop)959: {
963: switch (stop) {
964: case PEP_STOP_BASIC: pep->stopping = PEPStoppingBasic; break;
965: case PEP_STOP_USER:
966: if (!pep->stoppinguser) SETERRQ(PetscObjectComm((PetscObject)pep),PETSC_ERR_ORDER,"Must call PEPSetStoppingTestFunction() first");
967: pep->stopping = pep->stoppinguser;
968: break;
969: default:970: SETERRQ(PetscObjectComm((PetscObject)pep),PETSC_ERR_ARG_OUTOFRANGE,"Invalid 'stop' value");
971: }
972: pep->stop = stop;
973: return(0);
974: }
976: /*@
977: PEPGetStoppingTest - Gets the method used to decide the termination of the outer
978: loop of the eigensolver.
980: Not Collective
982: Input Parameters:
983: . pep - eigensolver context obtained from PEPCreate()
985: Output Parameters:
986: . stop - the type of stopping test
988: Level: advanced
990: .seealso: PEPSetStoppingTest(), PEPStop991: @*/
992: PetscErrorCode PEPGetStoppingTest(PEP pep,PEPStop *stop)993: {
997: *stop = pep->stop;
998: return(0);
999: }
1001: /*@
1002: PEPSetScale - Specifies the scaling strategy to be used.
1004: Logically Collective on pep
1006: Input Parameters:
1007: + pep - the eigensolver context
1008: . scale - scaling strategy
1009: . alpha - the scaling factor used in the scalar strategy
1010: . Dl - the left diagonal matrix of the diagonal scaling algorithm
1011: . Dr - the right diagonal matrix of the diagonal scaling algorithm
1012: . its - number of iterations of the diagonal scaling algorithm
1013: - lambda - approximation to wanted eigenvalues (modulus)
1015: Options Database Keys:
1016: + -pep_scale <type> - scaling type, one of <none,scalar,diagonal,both>
1017: . -pep_scale_factor <alpha> - the scaling factor
1018: . -pep_scale_its <its> - number of iterations
1019: - -pep_scale_lambda <lambda> - approximation to eigenvalues
1021: Notes:
1022: There are two non-exclusive scaling strategies: scalar and diagonal.
1024: In the scalar strategy, scaling is applied to the eigenvalue, that is,
1025: mu = lambda/alpha is the new eigenvalue and all matrices are scaled
1026: accordingly. After solving the scaled problem, the original lambda is
1027: recovered. Parameter 'alpha' must be positive. Use PETSC_DEFAULT to let
1028: the solver compute a reasonable scaling factor.
1030: In the diagonal strategy, the solver works implicitly with matrix Dl*A*Dr,
1031: where Dl and Dr are appropriate diagonal matrices. This improves the accuracy
1032: of the computed results in some cases. The user may provide the Dr and Dl
1033: matrices represented as Vec objects storing diagonal elements. If not
1034: provided, these matrices are computed internally. This option requires
1035: that the polynomial coefficient matrices are of MATAIJ type.
1036: The parameter 'its' is the number of iterations performed by the method.
1037: Parameter 'lambda' must be positive. Use PETSC_DEFAULT or set lambda = 1.0 if
1038: no information about eigenvalues is available.
1040: Level: intermediate
1042: .seealso: PEPGetScale()
1043: @*/
1044: PetscErrorCode PEPSetScale(PEP pep,PEPScale scale,PetscReal alpha,Vec Dl,Vec Dr,PetscInt its,PetscReal lambda)1045: {
1051: pep->scale = scale;
1052: if (scale==PEP_SCALE_SCALAR || scale==PEP_SCALE_BOTH) {
1054: if (alpha == PETSC_DEFAULT || alpha == PETSC_DECIDE) {
1055: pep->sfactor = 0.0;
1056: pep->sfactor_set = PETSC_FALSE;
1057: } else {
1058: if (alpha<=0.0) SETERRQ(PetscObjectComm((PetscObject)pep),PETSC_ERR_ARG_OUTOFRANGE,"Illegal value of alpha. Must be > 0");
1059: pep->sfactor = alpha;
1060: pep->sfactor_set = PETSC_TRUE;
1061: }
1062: }
1063: if (scale==PEP_SCALE_DIAGONAL || scale==PEP_SCALE_BOTH) {
1064: if (Dl) {
1067: PetscObjectReference((PetscObject)Dl);
1068: VecDestroy(&pep->Dl);
1069: pep->Dl = Dl;
1070: }
1071: if (Dr) {
1074: PetscObjectReference((PetscObject)Dr);
1075: VecDestroy(&pep->Dr);
1076: pep->Dr = Dr;
1077: }
1080: if (its==PETSC_DECIDE || its==PETSC_DEFAULT) pep->sits = 5;
1081: else pep->sits = its;
1082: if (lambda==PETSC_DECIDE || lambda==PETSC_DEFAULT) pep->slambda = 1.0;
1083: else if (lambda<=0.0) SETERRQ(PetscObjectComm((PetscObject)pep),PETSC_ERR_ARG_OUTOFRANGE,"Illegal value of lambda. Must be > 0");
1084: else pep->slambda = lambda;
1085: }
1086: pep->state = PEP_STATE_INITIAL;
1087: return(0);
1088: }
1090: /*@C
1091: PEPGetScale - Gets the scaling strategy used by the PEP object, and the
1092: associated parameters.
1094: Not Collectiv, but vectors are shared by all processors that share the PEP1096: Input Parameter:
1097: . pep - the eigensolver context
1099: Output Parameters:
1100: + scale - scaling strategy
1101: . alpha - the scaling factor used in the scalar strategy
1102: . Dl - the left diagonal matrix of the diagonal scaling algorithm
1103: . Dr - the right diagonal matrix of the diagonal scaling algorithm
1104: . its - number of iterations of the diagonal scaling algorithm
1105: - lambda - approximation to wanted eigenvalues (modulus)
1107: Level: intermediate
1109: Note:
1110: The user can specify NULL for any parameter that is not needed.
1112: If Dl or Dr were not set by the user, then the ones computed internally are
1113: returned (or a null pointer if called before PEPSetUp).
1115: .seealso: PEPSetScale(), PEPSetUp()
1116: @*/
1117: PetscErrorCode PEPGetScale(PEP pep,PEPScale *scale,PetscReal *alpha,Vec *Dl,Vec *Dr,PetscInt *its,PetscReal *lambda)1118: {
1121: if (scale) *scale = pep->scale;
1122: if (alpha) *alpha = pep->sfactor;
1123: if (Dl) *Dl = pep->Dl;
1124: if (Dr) *Dr = pep->Dr;
1125: if (its) *its = pep->sits;
1126: if (lambda) *lambda = pep->slambda;
1127: return(0);
1128: }
1130: /*@
1131: PEPSetExtract - Specifies the extraction strategy to be used.
1133: Logically Collective on pep
1135: Input Parameters:
1136: + pep - the eigensolver context
1137: - extract - extraction strategy
1139: Options Database Keys:
1140: . -pep_extract <type> - extraction type, one of <none,norm,residual,structured>
1142: Level: intermediate
1144: .seealso: PEPGetExtract()
1145: @*/
1146: PetscErrorCode PEPSetExtract(PEP pep,PEPExtract extract)1147: {
1151: pep->extract = extract;
1152: return(0);
1153: }
1155: /*@
1156: PEPGetExtract - Gets the extraction strategy used by the PEP object.
1158: Not Collective
1160: Input Parameter:
1161: . pep - the eigensolver context
1163: Output Parameter:
1164: . extract - extraction strategy
1166: Level: intermediate
1168: .seealso: PEPSetExtract(), PEPExtract1169: @*/
1170: PetscErrorCode PEPGetExtract(PEP pep,PEPExtract *extract)1171: {
1175: *extract = pep->extract;
1176: return(0);
1177: }
1179: /*@
1180: PEPSetRefine - Specifies the refinement type (and options) to be used
1181: after the solve.
1183: Logically Collective on pep
1185: Input Parameters:
1186: + pep - the polynomial eigensolver context
1187: . refine - refinement type
1188: . npart - number of partitions of the communicator
1189: . tol - the convergence tolerance
1190: . its - maximum number of refinement iterations
1191: - scheme - which scheme to be used for solving the involved linear systems
1193: Options Database Keys:
1194: + -pep_refine <type> - refinement type, one of <none,simple,multiple>
1195: . -pep_refine_partitions <n> - the number of partitions
1196: . -pep_refine_tol <tol> - the tolerance
1197: . -pep_refine_its <its> - number of iterations
1198: - -pep_refine_scheme - to set the scheme for the linear solves
1200: Notes:
1201: By default, iterative refinement is disabled, since it may be very
1202: costly. There are two possible refinement strategies: simple and multiple.
1203: The simple approach performs iterative refinement on each of the
1204: converged eigenpairs individually, whereas the multiple strategy works
1205: with the invariant pair as a whole, refining all eigenpairs simultaneously.
1206: The latter may be required for the case of multiple eigenvalues.
1208: In some cases, especially when using direct solvers within the
1209: iterative refinement method, it may be helpful for improved scalability
1210: to split the communicator in several partitions. The npart parameter
1211: indicates how many partitions to use (defaults to 1).
1213: The tol and its parameters specify the stopping criterion. In the simple
1214: method, refinement continues until the residual of each eigenpair is
1215: below the tolerance (tol defaults to the PEP tol, but may be set to a
1216: different value). In contrast, the multiple method simply performs its
1217: refinement iterations (just one by default).
1219: The scheme argument is used to change the way in which linear systems are
1220: solved. Possible choices are: explicit, mixed block elimination (MBE),
1221: and Schur complement.
1223: Level: intermediate
1225: .seealso: PEPGetRefine()
1226: @*/
1227: PetscErrorCode PEPSetRefine(PEP pep,PEPRefine refine,PetscInt npart,PetscReal tol,PetscInt its,PEPRefineScheme scheme)1228: {
1230: PetscMPIInt size;
1239: pep->refine = refine;
1240: if (refine) { /* process parameters only if not REFINE_NONE */
1241: if (npart!=pep->npart) {
1242: PetscSubcommDestroy(&pep->refinesubc);
1243: KSPDestroy(&pep->refineksp);
1244: }
1245: if (npart == PETSC_DEFAULT || npart == PETSC_DECIDE) {
1246: pep->npart = 1;
1247: } else {
1248: MPI_Comm_size(PetscObjectComm((PetscObject)pep),&size);
1249: if (npart<1 || npart>size) SETERRQ(PetscObjectComm((PetscObject)pep),PETSC_ERR_ARG_OUTOFRANGE,"Illegal value of npart");
1250: pep->npart = npart;
1251: }
1252: if (tol == PETSC_DEFAULT || tol == PETSC_DECIDE) {
1253: pep->rtol = PETSC_DEFAULT;
1254: } else {
1255: if (tol<=0.0) SETERRQ(PetscObjectComm((PetscObject)pep),PETSC_ERR_ARG_OUTOFRANGE,"Illegal value of tol. Must be > 0");
1256: pep->rtol = tol;
1257: }
1258: if (its==PETSC_DECIDE || its==PETSC_DEFAULT) {
1259: pep->rits = PETSC_DEFAULT;
1260: } else {
1261: if (its<0) SETERRQ(PetscObjectComm((PetscObject)pep),PETSC_ERR_ARG_OUTOFRANGE,"Illegal value of its. Must be >= 0");
1262: pep->rits = its;
1263: }
1264: pep->scheme = scheme;
1265: }
1266: pep->state = PEP_STATE_INITIAL;
1267: return(0);
1268: }
1270: /*@C
1271: PEPGetRefine - Gets the refinement strategy used by the PEP object, and the
1272: associated parameters.
1274: Not Collective
1276: Input Parameter:
1277: . pep - the polynomial eigensolver context
1279: Output Parameters:
1280: + refine - refinement type
1281: . npart - number of partitions of the communicator
1282: . tol - the convergence tolerance
1283: . its - maximum number of refinement iterations
1284: - scheme - the scheme used for solving linear systems
1286: Level: intermediate
1288: Note:
1289: The user can specify NULL for any parameter that is not needed.
1291: .seealso: PEPSetRefine()
1292: @*/
1293: PetscErrorCode PEPGetRefine(PEP pep,PEPRefine *refine,PetscInt *npart,PetscReal *tol,PetscInt *its,PEPRefineScheme *scheme)1294: {
1297: if (refine) *refine = pep->refine;
1298: if (npart) *npart = pep->npart;
1299: if (tol) *tol = pep->rtol;
1300: if (its) *its = pep->rits;
1301: if (scheme) *scheme = pep->scheme;
1302: return(0);
1303: }
1305: /*@C
1306: PEPSetOptionsPrefix - Sets the prefix used for searching for all
1307: PEP options in the database.
1309: Logically Collective on pep
1311: Input Parameters:
1312: + pep - the polynomial eigensolver context
1313: - prefix - the prefix string to prepend to all PEP option requests
1315: Notes:
1316: A hyphen (-) must NOT be given at the beginning of the prefix name.
1317: The first character of all runtime options is AUTOMATICALLY the
1318: hyphen.
1320: For example, to distinguish between the runtime options for two
1321: different PEP contexts, one could call
1322: .vb
1323: PEPSetOptionsPrefix(pep1,"qeig1_")
1324: PEPSetOptionsPrefix(pep2,"qeig2_")
1325: .ve
1327: Level: advanced
1329: .seealso: PEPAppendOptionsPrefix(), PEPGetOptionsPrefix()
1330: @*/
1331: PetscErrorCode PEPSetOptionsPrefix(PEP pep,const char *prefix)1332: {
1337: if (!pep->st) { PEPGetST(pep,&pep->st); }
1338: STSetOptionsPrefix(pep->st,prefix);
1339: if (!pep->V) { PEPGetBV(pep,&pep->V); }
1340: BVSetOptionsPrefix(pep->V,prefix);
1341: if (!pep->ds) { PEPGetDS(pep,&pep->ds); }
1342: DSSetOptionsPrefix(pep->ds,prefix);
1343: if (!pep->rg) { PEPGetRG(pep,&pep->rg); }
1344: RGSetOptionsPrefix(pep->rg,prefix);
1345: PetscObjectSetOptionsPrefix((PetscObject)pep,prefix);
1346: return(0);
1347: }
1349: /*@C
1350: PEPAppendOptionsPrefix - Appends to the prefix used for searching for all
1351: PEP options in the database.
1353: Logically Collective on pep
1355: Input Parameters:
1356: + pep - the polynomial eigensolver context
1357: - prefix - the prefix string to prepend to all PEP option requests
1359: Notes:
1360: A hyphen (-) must NOT be given at the beginning of the prefix name.
1361: The first character of all runtime options is AUTOMATICALLY the hyphen.
1363: Level: advanced
1365: .seealso: PEPSetOptionsPrefix(), PEPGetOptionsPrefix()
1366: @*/
1367: PetscErrorCode PEPAppendOptionsPrefix(PEP pep,const char *prefix)1368: {
1373: if (!pep->st) { PEPGetST(pep,&pep->st); }
1374: STAppendOptionsPrefix(pep->st,prefix);
1375: if (!pep->V) { PEPGetBV(pep,&pep->V); }
1376: BVAppendOptionsPrefix(pep->V,prefix);
1377: if (!pep->ds) { PEPGetDS(pep,&pep->ds); }
1378: DSAppendOptionsPrefix(pep->ds,prefix);
1379: if (!pep->rg) { PEPGetRG(pep,&pep->rg); }
1380: RGAppendOptionsPrefix(pep->rg,prefix);
1381: PetscObjectAppendOptionsPrefix((PetscObject)pep,prefix);
1382: return(0);
1383: }
1385: /*@C
1386: PEPGetOptionsPrefix - Gets the prefix used for searching for all
1387: PEP options in the database.
1389: Not Collective
1391: Input Parameters:
1392: . pep - the polynomial eigensolver context
1394: Output Parameters:
1395: . prefix - pointer to the prefix string used is returned
1397: Note:
1398: On the Fortran side, the user should pass in a string 'prefix' of
1399: sufficient length to hold the prefix.
1401: Level: advanced
1403: .seealso: PEPSetOptionsPrefix(), PEPAppendOptionsPrefix()
1404: @*/
1405: PetscErrorCode PEPGetOptionsPrefix(PEP pep,const char *prefix[])1406: {
1412: PetscObjectGetOptionsPrefix((PetscObject)pep,prefix);
1413: return(0);
1414: }