Actual source code: epsimpl.h
1: /*
2: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3: SLEPc - Scalable Library for Eigenvalue Problem Computations
4: Copyright (c) 2002-2010, Universidad Politecnica de Valencia, Spain
6: This file is part of SLEPc.
7:
8: SLEPc is free software: you can redistribute it and/or modify it under the
9: terms of version 3 of the GNU Lesser General Public License as published by
10: the Free Software Foundation.
12: SLEPc is distributed in the hope that it will be useful, but WITHOUT ANY
13: WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14: FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
15: more details.
17: You should have received a copy of the GNU Lesser General Public License
18: along with SLEPc. If not, see <http://www.gnu.org/licenses/>.
19: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
20: */
22: #ifndef _EPSIMPL
23: #define _EPSIMPL
25: #include slepceps.h
30: typedef struct _EPSOps *EPSOps;
32: struct _EPSOps {
33: PetscErrorCode (*solve)(EPS);
34: PetscErrorCode (*setup)(EPS);
35: PetscErrorCode (*setfromoptions)(EPS);
36: PetscErrorCode (*publishoptions)(EPS);
37: PetscErrorCode (*destroy)(EPS);
38: PetscErrorCode (*view)(EPS,PetscViewer);
39: PetscErrorCode (*backtransform)(EPS);
40: PetscErrorCode (*computevectors)(EPS);
41: };
43: /*
44: Maximum number of monitors you can run with a single EPS
45: */
46: #define MAXEPSMONITORS 5
48: /*
49: Defines the EPS data structure.
50: */
51: struct _p_EPS {
52: PETSCHEADER(struct _EPSOps);
53: /*------------------------- User parameters --------------------------*/
54: PetscInt max_it, /* maximum number of iterations */
55: nev, /* number of eigenvalues to compute */
56: ncv, /* number of basis vectors */
57: mpd, /* maximum dimension of projected problem */
58: nini, ninil, /* number of initial vectors (negative means not copied yet) */
59: nds; /* number of basis vectors of deflation space */
60: PetscScalar target; /* target value */
61: PetscReal tol; /* tolerance */
62: EPSConv conv; /* convergence test */
63: PetscErrorCode (*conv_func)(EPS,PetscScalar,PetscScalar,PetscReal,PetscReal*,void*);
64: void *conv_ctx;
65: EPSWhich which; /* which part of the spectrum to be sought */
66: PetscTruth leftvecs; /* if left eigenvectors are requested */
67: PetscErrorCode (*which_func)(EPS,PetscScalar,PetscScalar,PetscScalar,PetscScalar,PetscInt*,void*);
68: void *which_ctx;
69: EPSProblemType problem_type; /* which kind of problem to be solved */
70: EPSExtraction extraction; /* which kind of extraction to be applied */
71: EPSBalance balance; /* the balancing method */
72: PetscInt balance_its; /* number of iterations of the balancing method */
73: PetscReal balance_cutoff; /* cutoff value for balancing */
74: PetscReal nrma, nrmb; /* matrix norms */
75: PetscTruth adaptive; /* whether matrix norms are adaptively improved */
76: PetscTruth trueres; /* whether the true residual norm must be computed */
77: PetscTruth trackall; /* whether all the residuals must be computed */
79: /*------------------------- Working data --------------------------*/
80: Vec D, /* diagonal matrix for balancing */
81: *V, /* set of basis vectors and computed eigenvectors */
82: *W, /* set of left basis vectors and computed left eigenvectors */
83: *IS, *ISL, /* placeholder for references to user-provided initial space */
84: *DS; /* deflation space */
85: PetscScalar *eigr, *eigi, /* real and imaginary parts of eigenvalues */
86: *T, *Tl; /* projected matrices */
87: PetscReal *errest, /* error estimates */
88: *errest_left; /* left error estimates */
89: ST OP; /* spectral transformation object */
90: IP ip; /* innerproduct object */
91: void *data; /* placeholder for misc stuff associated
92: with a particular solver */
93: PetscInt nconv, /* number of converged eigenvalues */
94: its, /* number of iterations so far computed */
95: *perm, /* permutation for eigenvalue ordering */
96: nv, /* size of current Schur decomposition */
97: n, nloc, /* problem dimensions (global, local) */
98: allocated_ncv; /* number of basis vectors allocated */
99: PetscTruth evecsavailable; /* computed eigenvectors */
100: PetscRandom rand; /* random number generator */
102: /* ---------------- Default work-area and status vars -------------------- */
103: PetscInt nwork;
104: Vec *work;
106: PetscTruth ds_ortho; /* if DS vectors have been stored and orthonormalized */
107: PetscInt setupcalled;
108: PetscTruth isgeneralized,
109: ispositive,
110: ishermitian;
111: EPSConvergedReason reason;
113: PetscErrorCode (*monitor[MAXEPSMONITORS])(EPS,PetscInt,PetscInt,PetscScalar*,PetscScalar*,PetscReal*,PetscInt,void*);
114: PetscErrorCode (*monitordestroy[MAXEPSMONITORS])(void*);
115: void *monitorcontext[MAXEPSMONITORS];
116: PetscInt numbermonitors;
117: };
119: #define EPSMonitor(eps,it,nconv,eigr,eigi,errest,nest) \
120: { PetscErrorCode _ierr; PetscInt _i,_im = eps->numbermonitors; \
121: for ( _i=0; _i<_im; _i++ ) {\
122: _ierr=(*eps->monitor[_i])(eps,it,nconv,eigr,eigi,errest,nest,eps->monitorcontext[_i]);\
123: CHKERRQ(_ierr); \
124: } \
125: }
127: /* context for EPSMonitorConverged */
128: typedef struct {
129: PetscViewerASCIIMonitor viewer;
130: PetscInt oldnconv;
131: } EPSMONITOR_CONV;
132: EXTERN PetscErrorCode EPSMonitorDestroy_Converged(EPSMONITOR_CONV*);
134: EXTERN PetscErrorCode EPSRegisterAll(char *);
135: EXTERN PetscErrorCode EPSInitializePackage(char *);
136: EXTERN PetscErrorCode EPSFinalizePackage(void);
138: EXTERN PetscErrorCode EPSDestroy_Default(EPS);
139: EXTERN PetscErrorCode EPSDefaultGetWork(EPS,PetscInt);
140: EXTERN PetscErrorCode EPSDefaultFreeWork(EPS);
141: EXTERN PetscErrorCode EPSAllocateSolution(EPS);
142: EXTERN PetscErrorCode EPSFreeSolution(EPS);
143: EXTERN PetscErrorCode EPSBackTransform_Default(EPS);
144: EXTERN PetscErrorCode EPSComputeVectors_Default(EPS);
145: EXTERN PetscErrorCode EPSComputeVectors_Hermitian(EPS);
146: EXTERN PetscErrorCode EPSComputeVectors_Schur(EPS);
147: EXTERN PetscErrorCode EPSComputeResidualNorm_Private(EPS,PetscScalar,PetscScalar,Vec,Vec,PetscReal*);
148: EXTERN PetscErrorCode EPSComputeRelativeError_Private(EPS,PetscScalar,PetscScalar,Vec,Vec,PetscReal*);
149: EXTERN PetscErrorCode EPSComputeTrueResidual(EPS,PetscScalar,PetscScalar,PetscScalar*,Vec*,PetscInt,PetscReal*);
151: /* Private functions of the solver implementations */
153: EXTERN PetscErrorCode EPSBasicArnoldi(EPS,PetscTruth,PetscScalar*,PetscInt,Vec*,PetscInt,PetscInt*,Vec,PetscReal*,PetscTruth*);
154: EXTERN PetscErrorCode EPSDelayedArnoldi(EPS,PetscScalar*,PetscInt,Vec*,PetscInt,PetscInt*,Vec,PetscReal*,PetscTruth*);
155: EXTERN PetscErrorCode EPSDelayedArnoldi1(EPS,PetscScalar*,PetscInt,Vec*,PetscInt,PetscInt*,Vec,PetscReal*,PetscTruth*);
156: EXTERN PetscErrorCode EPSKrylovConvergence(EPS,PetscTruth,PetscInt,PetscInt,PetscScalar*,PetscInt,PetscScalar*,Vec*,PetscInt,PetscReal,PetscReal,PetscInt*,PetscScalar*);
157: EXTERN PetscErrorCode EPSFullLanczos(EPS,PetscReal*,PetscReal*,Vec*,PetscInt,PetscInt*,Vec,PetscTruth*);
158: EXTERN PetscErrorCode EPSTranslateHarmonic(PetscInt,PetscScalar*,PetscInt,PetscScalar,PetscScalar,PetscScalar*,PetscScalar*);
159: EXTERN PetscErrorCode EPSBuildBalance_Krylov(EPS);
160: EXTERN PetscErrorCode EPSProjectedKSNonsym(EPS,PetscInt,PetscScalar*,PetscInt,PetscScalar*,PetscInt);
162: #endif