| 531 |
dsic.upv.es!jroman |
1 |
/*
|
| 6 |
dsic.upv.es!jroman |
2 |
|
| 531 |
dsic.upv.es!jroman |
3 |
SLEPc eigensolver: "power"
|
|
|
4 |
|
|
|
5 |
Method: Power Iteration
|
|
|
6 |
|
|
|
7 |
Description:
|
|
|
8 |
|
|
|
9 |
This solver implements the power iteration for finding dominant
|
|
|
10 |
eigenpairs. It also includes the following well-known methods:
|
|
|
11 |
- Inverse Iteration: when used in combination with shift-and-invert
|
|
|
12 |
spectral transformation.
|
|
|
13 |
- Rayleigh Quotient Iteration (RQI): also with shift-and-invert plus
|
|
|
14 |
a variable shift.
|
|
|
15 |
|
|
|
16 |
Algorithm:
|
|
|
17 |
|
|
|
18 |
The implemented algorithm is the simple power iteration working with
|
|
|
19 |
OP, the operator provided by the ST object. Converged eigenpairs are
|
|
|
20 |
deflated by restriction, so that several eigenpairs can be sought.
|
|
|
21 |
Symmetry is preserved in symmetric definite pencils. See the SLEPc
|
|
|
22 |
users guide for details.
|
|
|
23 |
|
|
|
24 |
Variable shifts can be used. There are two possible strategies for
|
|
|
25 |
updating shift: Rayleigh quotients and Wilkinson shifts.
|
|
|
26 |
|
|
|
27 |
References:
|
|
|
28 |
|
|
|
29 |
[1] B.N. Parlett, "The Symmetric Eigenvalue Problem", SIAM Classics in
|
|
|
30 |
Applied Mathematics (1998), pp 61-80 and 159-165.
|
|
|
31 |
|
|
|
32 |
Last update: June 2004
|
|
|
33 |
|
| 6 |
dsic.upv.es!jroman |
34 |
*/
|
| 458 |
dsic.upv.es!antodo |
35 |
#include "src/eps/epsimpl.h" /*I "slepceps.h" I*/
|
| 444 |
dsic.upv.es!antodo |
36 |
#include "slepcblaslapack.h"
|
| 6 |
dsic.upv.es!jroman |
37 |
|
| 444 |
dsic.upv.es!antodo |
38 |
typedef struct {
|
|
|
39 |
EPSPowerShiftType shift_type;
|
|
|
40 |
} EPS_POWER;
|
|
|
41 |
|
| 6 |
dsic.upv.es!jroman |
42 |
#undef __FUNCT__
|
|
|
43 |
#define __FUNCT__ "EPSSetUp_POWER"
|
| 476 |
dsic.upv.es!antodo |
44 |
PetscErrorCode EPSSetUp_POWER(EPS eps)
|
| 6 |
dsic.upv.es!jroman |
45 |
{
|
| 476 |
dsic.upv.es!antodo |
46 |
PetscErrorCode ierr;
|
|
|
47 |
EPS_POWER *power = (EPS_POWER *)eps->data;
|
|
|
48 |
int N;
|
|
|
49 |
PetscTruth flg;
|
|
|
50 |
STMatMode mode;
|
| 6 |
dsic.upv.es!jroman |
51 |
|
|
|
52 |
PetscFunctionBegin;
|
|
|
53 |
ierr = VecGetSize(eps->vec_initial,&N);CHKERRQ(ierr);
|
|
|
54 |
if (eps->ncv) {
|
|
|
55 |
if (eps->ncv<eps->nev) SETERRQ(1,"The value of ncv must be at least nev");
|
|
|
56 |
}
|
|
|
57 |
else eps->ncv = eps->nev;
|
|
|
58 |
if (!eps->max_it) eps->max_it = PetscMax(2000,100*N);
|
|
|
59 |
if (!eps->tol) eps->tol = 1.e-7;
|
| 259 |
dsic.upv.es!antodo |
60 |
if (eps->which!=EPS_LARGEST_MAGNITUDE)
|
|
|
61 |
SETERRQ(1,"Wrong value of eps->which");
|
| 444 |
dsic.upv.es!antodo |
62 |
if (power->shift_type != EPSPOWER_SHIFT_CONSTANT) {
|
|
|
63 |
ierr = PetscTypeCompare((PetscObject)eps->OP,STSHIFT,&flg);CHKERRQ(ierr);
|
|
|
64 |
if (flg)
|
|
|
65 |
SETERRQ(PETSC_ERR_SUP,"Shift spectral transformation does not work with variable shifts");
|
|
|
66 |
ierr = STGetMatMode(eps->OP,&mode);CHKERRQ(ierr);
|
|
|
67 |
if (mode == STMATMODE_INPLACE)
|
|
|
68 |
SETERRQ(PETSC_ERR_SUP,"ST matrix mode inplace does not work with variable shifts");
|
|
|
69 |
}
|
| 259 |
dsic.upv.es!antodo |
70 |
ierr = EPSAllocateSolution(eps);CHKERRQ(ierr);
|
| 444 |
dsic.upv.es!antodo |
71 |
ierr = EPSDefaultGetWork(eps,2);CHKERRQ(ierr);
|
| 6 |
dsic.upv.es!jroman |
72 |
PetscFunctionReturn(0);
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
#undef __FUNCT__
|
| 446 |
dsic.upv.es!jroman |
76 |
#define __FUNCT__ "EPSPowerUpdateShift"
|
| 531 |
dsic.upv.es!jroman |
77 |
/*
|
|
|
78 |
EPSPowerUpdateShift - Computes the new shift to be used in the next
|
|
|
79 |
iteration of the power method. This function is invoked only when using
|
|
|
80 |
the option of variable shifts (see EPSPowerSetShiftType).
|
|
|
81 |
*/
|
| 780 |
dsic.upv.es!jroman |
82 |
static PetscErrorCode EPSPowerUpdateShift(EPS eps,Vec v,Vec w,PetscScalar* shift)
|
| 446 |
dsic.upv.es!jroman |
83 |
{
|
| 476 |
dsic.upv.es!antodo |
84 |
PetscErrorCode ierr;
|
|
|
85 |
EPS_POWER *power = (EPS_POWER *)eps->data;
|
| 780 |
dsic.upv.es!jroman |
86 |
Vec e, z;
|
| 476 |
dsic.upv.es!antodo |
87 |
Mat A;
|
|
|
88 |
PetscReal norm, rt1, rt2, cs1;
|
|
|
89 |
PetscScalar alpha, alpha1, alpha2, beta1, sn1;
|
| 446 |
dsic.upv.es!jroman |
90 |
|
|
|
91 |
PetscFunctionBegin;
|
|
|
92 |
e = eps->work[0];
|
| 780 |
dsic.upv.es!jroman |
93 |
z = eps->work[1];
|
| 446 |
dsic.upv.es!jroman |
94 |
ierr = STGetOperators(eps->OP,&A,PETSC_NULL);CHKERRQ(ierr);
|
| 531 |
dsic.upv.es!jroman |
95 |
|
| 780 |
dsic.upv.es!jroman |
96 |
/* compute the generalized Rayleigh quotient R(v,w) assuming (v,w)_B=1 */
|
| 446 |
dsic.upv.es!jroman |
97 |
ierr = MatMult(A,v,e);CHKERRQ(ierr);
|
| 780 |
dsic.upv.es!jroman |
98 |
ierr = VecDot(w,e,&alpha1);CHKERRQ(ierr);
|
| 531 |
dsic.upv.es!jroman |
99 |
|
|
|
100 |
/* in the case of Wilkinson the shift is improved */
|
| 446 |
dsic.upv.es!jroman |
101 |
if (power->shift_type == EPSPOWER_SHIFT_WILKINSON) {
|
| 509 |
dsic.upv.es!antodo |
102 |
#if defined(PETSC_BLASLAPACK_ESSL_ONLY)
|
|
|
103 |
SETERRQ(PETSC_ERR_SUP,"LAEV2 - Lapack routine is unavailable.");
|
|
|
104 |
#endif
|
| 531 |
dsic.upv.es!jroman |
105 |
/* beta1 is the norm of the residual associated to R(v) */
|
| 446 |
dsic.upv.es!jroman |
106 |
alpha = -alpha1;
|
|
|
107 |
ierr = VecAXPY(&alpha,v,e);CHKERRQ(ierr);
|
|
|
108 |
ierr = STNorm(eps->OP,e,&norm);CHKERRQ(ierr);
|
|
|
109 |
beta1 = norm;
|
| 531 |
dsic.upv.es!jroman |
110 |
|
|
|
111 |
/* alfa2 = (e'*A*e)/(beta1*beta1), where e is the residual */
|
| 780 |
dsic.upv.es!jroman |
112 |
ierr = MatMult(A,e,z);CHKERRQ(ierr);
|
|
|
113 |
ierr = VecDot(e,z,&alpha2);CHKERRQ(ierr);
|
| 446 |
dsic.upv.es!jroman |
114 |
alpha2 = alpha2 / (beta1 * beta1);
|
| 531 |
dsic.upv.es!jroman |
115 |
|
|
|
116 |
/* choose the eigenvalue of [alfa1 beta1; beta1 alfa2] closest to alpha1 */
|
| 784 |
dsic.upv.es!antodo |
117 |
LAPACKlaev2_(&alpha1,&beta1,&alpha2,&rt1,&rt2,&cs1,&sn1);
|
| 446 |
dsic.upv.es!jroman |
118 |
if (PetscAbsScalar(rt1-alpha1) < PetscAbsScalar(rt2-alpha1)) {
|
|
|
119 |
*shift = rt1;
|
|
|
120 |
} else {
|
|
|
121 |
*shift = rt2;
|
|
|
122 |
}
|
|
|
123 |
}
|
|
|
124 |
else *shift = alpha1;
|
|
|
125 |
|
|
|
126 |
PetscFunctionReturn(0);
|
|
|
127 |
}
|
|
|
128 |
|
|
|
129 |
#undef __FUNCT__
|
| 6 |
dsic.upv.es!jroman |
130 |
#define __FUNCT__ "EPSSolve_POWER"
|
| 476 |
dsic.upv.es!antodo |
131 |
PetscErrorCode EPSSolve_POWER(EPS eps)
|
| 6 |
dsic.upv.es!jroman |
132 |
{
|
| 476 |
dsic.upv.es!antodo |
133 |
PetscErrorCode ierr;
|
|
|
134 |
EPS_POWER *power = (EPS_POWER *)eps->data;
|
|
|
135 |
int i;
|
| 531 |
dsic.upv.es!jroman |
136 |
Vec v, y, e;
|
| 476 |
dsic.upv.es!antodo |
137 |
PetscReal relerr, norm;
|
|
|
138 |
PetscScalar theta, alpha, rho;
|
| 6 |
dsic.upv.es!jroman |
139 |
|
|
|
140 |
PetscFunctionBegin;
|
|
|
141 |
v = eps->V[0];
|
| 428 |
dsic.upv.es!jroman |
142 |
y = eps->AV[0];
|
|
|
143 |
e = eps->work[0];
|
| 6 |
dsic.upv.es!jroman |
144 |
|
|
|
145 |
ierr = VecCopy(eps->vec_initial,y);CHKERRQ(ierr);
|
|
|
146 |
|
| 252 |
dsic.upv.es!jroman |
147 |
eps->nconv = 0;
|
|
|
148 |
eps->its = 0;
|
| 6 |
dsic.upv.es!jroman |
149 |
|
| 281 |
dsic.upv.es!antodo |
150 |
for (i=0;i<eps->ncv;i++) eps->eigi[i]=0.0;
|
|
|
151 |
|
| 428 |
dsic.upv.es!jroman |
152 |
while (eps->its<eps->max_it) {
|
| 252 |
dsic.upv.es!jroman |
153 |
|
| 450 |
dsic.upv.es!antodo |
154 |
/* deflation of converged eigenvectors */
|
|
|
155 |
ierr = EPSPurge(eps,y);
|
|
|
156 |
|
| 428 |
dsic.upv.es!jroman |
157 |
/* v = y/||y||_B */
|
|
|
158 |
ierr = VecCopy(y,v);CHKERRQ(ierr);
|
|
|
159 |
ierr = STNorm(eps->OP,y,&norm);CHKERRQ(ierr);
|
|
|
160 |
alpha = 1.0/norm;
|
|
|
161 |
ierr = VecScale(&alpha,v);CHKERRQ(ierr);
|
| 6 |
dsic.upv.es!jroman |
162 |
|
| 428 |
dsic.upv.es!jroman |
163 |
/* y = OP v */
|
|
|
164 |
ierr = STApply(eps->OP,v,y);CHKERRQ(ierr);
|
| 6 |
dsic.upv.es!jroman |
165 |
|
| 531 |
dsic.upv.es!jroman |
166 |
/* theta = (y,v)_B */
|
| 428 |
dsic.upv.es!jroman |
167 |
ierr = STInnerProduct(eps->OP,y,v,&theta);CHKERRQ(ierr);
|
| 6 |
dsic.upv.es!jroman |
168 |
|
| 446 |
dsic.upv.es!jroman |
169 |
/* compute residual norm */
|
| 6 |
dsic.upv.es!jroman |
170 |
ierr = VecCopy(y,e);CHKERRQ(ierr);
|
|
|
171 |
alpha = -theta;
|
|
|
172 |
ierr = VecAXPY(&alpha,v,e);CHKERRQ(ierr);
|
|
|
173 |
ierr = VecNorm(e,NORM_2,&relerr);CHKERRQ(ierr);
|
|
|
174 |
relerr = relerr / PetscAbsScalar(theta);
|
|
|
175 |
eps->errest[eps->nconv] = relerr;
|
| 252 |
dsic.upv.es!jroman |
176 |
|
| 450 |
dsic.upv.es!antodo |
177 |
/* update eigenvalue and shift */
|
| 444 |
dsic.upv.es!antodo |
178 |
if (power->shift_type != EPSPOWER_SHIFT_CONSTANT) {
|
| 780 |
dsic.upv.es!jroman |
179 |
ierr = EPSPowerUpdateShift(eps,v,v,&rho);CHKERRQ(ierr);
|
| 531 |
dsic.upv.es!jroman |
180 |
/* change the shift only if rho is not too close to an eigenvalue */
|
| 450 |
dsic.upv.es!antodo |
181 |
if (relerr > 1000*eps->tol) {
|
|
|
182 |
ierr = STSetShift(eps->OP,rho);CHKERRQ(ierr);
|
|
|
183 |
}
|
|
|
184 |
eps->eigr[eps->nconv] = rho;
|
| 444 |
dsic.upv.es!antodo |
185 |
} else {
|
|
|
186 |
eps->eigr[eps->nconv] = theta;
|
|
|
187 |
}
|
|
|
188 |
|
| 446 |
dsic.upv.es!jroman |
189 |
/* if ||y-theta v||_2 / |theta| < tol, accept eigenpair */
|
| 428 |
dsic.upv.es!jroman |
190 |
if (relerr<eps->tol) {
|
| 6 |
dsic.upv.es!jroman |
191 |
eps->nconv = eps->nconv + 1;
|
|
|
192 |
if (eps->nconv==eps->nev) break;
|
|
|
193 |
v = eps->V[eps->nconv];
|
|
|
194 |
}
|
|
|
195 |
|
| 281 |
dsic.upv.es!antodo |
196 |
EPSMonitor(eps,eps->its,eps->nconv,eps->eigr,eps->eigi,eps->errest,eps->nconv+1);
|
| 624 |
dsic.upv.es!antodo |
197 |
eps->its = eps->its + 1;
|
| 6 |
dsic.upv.es!jroman |
198 |
}
|
|
|
199 |
|
|
|
200 |
if( eps->nconv == eps->nev ) eps->reason = EPS_CONVERGED_TOL;
|
|
|
201 |
else eps->reason = EPS_DIVERGED_ITS;
|
|
|
202 |
|
|
|
203 |
PetscFunctionReturn(0);
|
|
|
204 |
}
|
|
|
205 |
|
| 444 |
dsic.upv.es!antodo |
206 |
#undef __FUNCT__
|
| 780 |
dsic.upv.es!jroman |
207 |
#define __FUNCT__ "EPSSolve_TS_POWER"
|
|
|
208 |
PetscErrorCode EPSSolve_TS_POWER(EPS eps)
|
|
|
209 |
{
|
|
|
210 |
PetscErrorCode ierr;
|
|
|
211 |
EPS_POWER *power = (EPS_POWER *)eps->data;
|
|
|
212 |
int i;
|
|
|
213 |
Vec v, w, y, z, e;
|
|
|
214 |
PetscReal relerr;
|
|
|
215 |
PetscScalar theta, alpha, rho;
|
|
|
216 |
|
|
|
217 |
PetscFunctionBegin;
|
|
|
218 |
v = eps->V[0];
|
|
|
219 |
y = eps->AV[0];
|
|
|
220 |
w = eps->W[0];
|
|
|
221 |
z = eps->AW[0];
|
|
|
222 |
e = eps->work[0];
|
|
|
223 |
|
|
|
224 |
ierr = VecCopy(eps->vec_initial,y);CHKERRQ(ierr);
|
|
|
225 |
ierr = VecCopy(eps->vec_initial_left,z);CHKERRQ(ierr);
|
|
|
226 |
|
|
|
227 |
eps->nconv = 0;
|
|
|
228 |
eps->its = 0;
|
|
|
229 |
|
|
|
230 |
for (i=0;i<eps->ncv;i++) eps->eigi[i]=0.0;
|
|
|
231 |
|
|
|
232 |
while (eps->its<eps->max_it) {
|
|
|
233 |
|
|
|
234 |
/* deflation of converged eigenvectors */
|
|
|
235 |
ierr = EPSBiOrthogonalize(eps,eps->nconv,eps->V,eps->W,z,PETSC_NULL,PETSC_NULL);CHKERRQ(ierr);
|
|
|
236 |
ierr = EPSBiOrthogonalize(eps,eps->nconv,eps->W,eps->V,y,PETSC_NULL,PETSC_NULL);CHKERRQ(ierr);
|
|
|
237 |
|
|
|
238 |
/* normalize so that (y,z)_B=1 */
|
|
|
239 |
ierr = VecCopy(y,v);CHKERRQ(ierr);
|
|
|
240 |
ierr = VecCopy(z,w);CHKERRQ(ierr);
|
|
|
241 |
ierr = STInnerProduct(eps->OP,y,z,&alpha);CHKERRQ(ierr);
|
|
|
242 |
if (alpha==0.0) SETERRQ(1,"Breakdown in two-sided Power/RQI");
|
|
|
243 |
if (alpha>0.0) {
|
|
|
244 |
alpha = 1.0/PetscSqrtScalar(alpha);
|
|
|
245 |
ierr = VecScale(&alpha,v);CHKERRQ(ierr);
|
|
|
246 |
ierr = VecScale(&alpha,w);CHKERRQ(ierr);
|
|
|
247 |
} else {
|
|
|
248 |
alpha = 1.0/PetscSqrtScalar(-alpha);
|
|
|
249 |
ierr = VecScale(&alpha,v);CHKERRQ(ierr);
|
|
|
250 |
alpha = -alpha;
|
|
|
251 |
ierr = VecScale(&alpha,w);CHKERRQ(ierr);
|
|
|
252 |
}
|
|
|
253 |
|
|
|
254 |
/* y = OP v */
|
|
|
255 |
ierr = STApply(eps->OP,v,y);CHKERRQ(ierr);
|
|
|
256 |
ierr = STApplyTranspose(eps->OP,w,z);CHKERRQ(ierr);
|
|
|
257 |
|
|
|
258 |
/* theta = (y,w)_B */
|
|
|
259 |
ierr = STInnerProduct(eps->OP,y,w,&theta);CHKERRQ(ierr);
|
|
|
260 |
|
|
|
261 |
/* compute residual norm */
|
|
|
262 |
ierr = VecCopy(y,e);CHKERRQ(ierr);
|
|
|
263 |
alpha = -theta;
|
|
|
264 |
ierr = VecAXPY(&alpha,v,e);CHKERRQ(ierr);
|
|
|
265 |
ierr = VecNorm(e,NORM_2,&relerr);CHKERRQ(ierr);
|
|
|
266 |
relerr = relerr / PetscAbsScalar(theta);
|
|
|
267 |
eps->errest[eps->nconv] = relerr;
|
|
|
268 |
ierr = VecCopy(z,e);CHKERRQ(ierr);
|
|
|
269 |
alpha = -theta;
|
|
|
270 |
ierr = VecAXPY(&alpha,w,e);CHKERRQ(ierr);
|
|
|
271 |
ierr = VecNorm(e,NORM_2,&relerr);CHKERRQ(ierr);
|
|
|
272 |
relerr = relerr / PetscAbsScalar(theta);
|
|
|
273 |
eps->errest_left[eps->nconv] = relerr;
|
|
|
274 |
|
|
|
275 |
/* update eigenvalue and shift */
|
|
|
276 |
if (power->shift_type != EPSPOWER_SHIFT_CONSTANT) {
|
|
|
277 |
ierr = EPSPowerUpdateShift(eps,v,w,&rho);CHKERRQ(ierr);
|
|
|
278 |
/* change the shift only if rho is not too close to an eigenvalue */
|
|
|
279 |
if (relerr > 1000*eps->tol) {
|
|
|
280 |
ierr = STSetShift(eps->OP,rho);CHKERRQ(ierr);
|
|
|
281 |
}
|
|
|
282 |
eps->eigr[eps->nconv] = rho;
|
|
|
283 |
} else {
|
|
|
284 |
eps->eigr[eps->nconv] = theta;
|
|
|
285 |
}
|
|
|
286 |
|
|
|
287 |
/* if ||y-theta v||_2 / |theta| < tol, accept eigenpair */
|
|
|
288 |
if (eps->errest[eps->nconv]<eps->tol && eps->errest_left[eps->nconv]<eps->tol) {
|
|
|
289 |
eps->nconv = eps->nconv + 1;
|
|
|
290 |
if (eps->nconv==eps->nev) break;
|
|
|
291 |
v = eps->V[eps->nconv];
|
|
|
292 |
w = eps->W[eps->nconv];
|
|
|
293 |
}
|
|
|
294 |
|
|
|
295 |
EPSMonitor(eps,eps->its,eps->nconv,eps->eigr,eps->eigi,eps->errest_left,eps->nconv+1);
|
|
|
296 |
eps->its = eps->its + 1;
|
|
|
297 |
}
|
|
|
298 |
|
|
|
299 |
if( eps->nconv == eps->nev ) eps->reason = EPS_CONVERGED_TOL;
|
|
|
300 |
else eps->reason = EPS_DIVERGED_ITS;
|
|
|
301 |
|
|
|
302 |
PetscFunctionReturn(0);
|
|
|
303 |
}
|
|
|
304 |
|
|
|
305 |
#undef __FUNCT__
|
| 444 |
dsic.upv.es!antodo |
306 |
#define __FUNCT__ "EPSBackTransform_POWER"
|
| 476 |
dsic.upv.es!antodo |
307 |
PetscErrorCode EPSBackTransform_POWER(EPS eps)
|
| 444 |
dsic.upv.es!antodo |
308 |
{
|
| 476 |
dsic.upv.es!antodo |
309 |
PetscErrorCode ierr;
|
| 444 |
dsic.upv.es!antodo |
310 |
EPS_POWER *power = (EPS_POWER *)eps->data;
|
|
|
311 |
|
|
|
312 |
PetscFunctionBegin;
|
|
|
313 |
if (power->shift_type == EPSPOWER_SHIFT_CONSTANT) {
|
|
|
314 |
ierr = EPSBackTransform_Default(eps);CHKERRQ(ierr);
|
|
|
315 |
}
|
|
|
316 |
PetscFunctionReturn(0);
|
|
|
317 |
}
|
|
|
318 |
|
|
|
319 |
#undef __FUNCT__
|
|
|
320 |
#define __FUNCT__ "EPSSetFromOptions_POWER"
|
| 476 |
dsic.upv.es!antodo |
321 |
PetscErrorCode EPSSetFromOptions_POWER(EPS eps)
|
| 444 |
dsic.upv.es!antodo |
322 |
{
|
| 476 |
dsic.upv.es!antodo |
323 |
PetscErrorCode ierr;
|
|
|
324 |
EPS_POWER *power = (EPS_POWER *)eps->data;
|
|
|
325 |
PetscTruth flg;
|
|
|
326 |
const char *shift_list[3] = { "constant", "rayleigh", "wilkinson" };
|
| 444 |
dsic.upv.es!antodo |
327 |
|
|
|
328 |
PetscFunctionBegin;
|
|
|
329 |
ierr = PetscOptionsHead("POWER options");CHKERRQ(ierr);
|
|
|
330 |
ierr = PetscOptionsEList("-eps_power_shift_type","Shift type","EPSPowerSetShiftType",shift_list,3,shift_list[power->shift_type],(int*)&power->shift_type,&flg);CHKERRQ(ierr);
|
|
|
331 |
if (power->shift_type != EPSPOWER_SHIFT_CONSTANT) {
|
|
|
332 |
ierr = STSetType(eps->OP,STSINV);CHKERRQ(ierr);
|
|
|
333 |
}
|
|
|
334 |
ierr = PetscOptionsTail();CHKERRQ(ierr);
|
|
|
335 |
PetscFunctionReturn(0);
|
|
|
336 |
}
|
|
|
337 |
|
| 6 |
dsic.upv.es!jroman |
338 |
EXTERN_C_BEGIN
|
|
|
339 |
#undef __FUNCT__
|
| 444 |
dsic.upv.es!antodo |
340 |
#define __FUNCT__ "EPSPowerSetShiftType_POWER"
|
| 476 |
dsic.upv.es!antodo |
341 |
PetscErrorCode EPSPowerSetShiftType_POWER(EPS eps,EPSPowerShiftType shift)
|
| 444 |
dsic.upv.es!antodo |
342 |
{
|
| 476 |
dsic.upv.es!antodo |
343 |
EPS_POWER *power = (EPS_POWER *)eps->data;
|
| 444 |
dsic.upv.es!antodo |
344 |
|
|
|
345 |
PetscFunctionBegin;
|
|
|
346 |
switch (shift) {
|
|
|
347 |
case EPSPOWER_SHIFT_CONSTANT:
|
|
|
348 |
case EPSPOWER_SHIFT_RAYLEIGH:
|
|
|
349 |
case EPSPOWER_SHIFT_WILKINSON:
|
|
|
350 |
power->shift_type = shift;
|
|
|
351 |
break;
|
|
|
352 |
default:
|
|
|
353 |
SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,"Invalid shift type");
|
|
|
354 |
}
|
|
|
355 |
PetscFunctionReturn(0);
|
|
|
356 |
}
|
|
|
357 |
EXTERN_C_END
|
|
|
358 |
|
|
|
359 |
#undef __FUNCT__
|
|
|
360 |
#define __FUNCT__ "EPSPowerSetShiftType"
|
| 446 |
dsic.upv.es!jroman |
361 |
/*@
|
|
|
362 |
EPSPowerSetShiftType - Sets the type of shifts used during the power
|
|
|
363 |
iteration. This can be used to emulate the Rayleigh Quotient Iteration
|
|
|
364 |
(RQI) method.
|
|
|
365 |
|
|
|
366 |
Collective on EPS
|
|
|
367 |
|
|
|
368 |
Input Parameters:
|
|
|
369 |
+ eps - the eigenproblem solver context
|
|
|
370 |
- shift - the type of shift
|
|
|
371 |
|
|
|
372 |
Options Database Key:
|
|
|
373 |
. -eps_power_shift_type - Sets the shift type (either 'constant' or
|
|
|
374 |
'rayleigh' or 'wilkinson')
|
|
|
375 |
|
|
|
376 |
Notes:
|
|
|
377 |
By default, shifts are constant (EPSPOWER_SHIFT_CONSTANT) and the iteration
|
|
|
378 |
is the simple power method (or inverse iteration if a shift-and-invert
|
|
|
379 |
transformation is being used).
|
|
|
380 |
|
|
|
381 |
A variable shift can be specified (EPSPOWER_SHIFT_RAYLEIGH or
|
|
|
382 |
EPSPOWER_SHIFT_WILKINSON). In this case, the iteration behaves rather like
|
|
|
383 |
a cubic converging method as RQI. See the users manual for details.
|
|
|
384 |
|
|
|
385 |
Level: advanced
|
|
|
386 |
|
|
|
387 |
.seealso: EPSGetShiftType(), STSetShift()
|
|
|
388 |
@*/
|
| 476 |
dsic.upv.es!antodo |
389 |
PetscErrorCode EPSPowerSetShiftType(EPS eps,EPSPowerShiftType shift)
|
| 444 |
dsic.upv.es!antodo |
390 |
{
|
| 476 |
dsic.upv.es!antodo |
391 |
PetscErrorCode ierr, (*f)(EPS,EPSPowerShiftType);
|
| 444 |
dsic.upv.es!antodo |
392 |
|
|
|
393 |
PetscFunctionBegin;
|
|
|
394 |
PetscValidHeaderSpecific(eps,EPS_COOKIE,1);
|
|
|
395 |
ierr = PetscObjectQueryFunction((PetscObject)eps,"EPSPowerSetShiftType_C",(void (**)())&f);CHKERRQ(ierr);
|
|
|
396 |
if (f) {
|
|
|
397 |
ierr = (*f)(eps,shift);CHKERRQ(ierr);
|
|
|
398 |
}
|
|
|
399 |
PetscFunctionReturn(0);
|
|
|
400 |
}
|
|
|
401 |
|
|
|
402 |
EXTERN_C_BEGIN
|
|
|
403 |
#undef __FUNCT__
|
|
|
404 |
#define __FUNCT__ "EPSPowerGetShiftType_POWER"
|
| 476 |
dsic.upv.es!antodo |
405 |
PetscErrorCode EPSPowerGetShiftType_POWER(EPS eps,EPSPowerShiftType *shift)
|
| 444 |
dsic.upv.es!antodo |
406 |
{
|
|
|
407 |
EPS_POWER *power = (EPS_POWER *)eps->data;
|
|
|
408 |
PetscFunctionBegin;
|
|
|
409 |
*shift = power->shift_type;
|
|
|
410 |
PetscFunctionReturn(0);
|
|
|
411 |
}
|
|
|
412 |
EXTERN_C_END
|
|
|
413 |
|
|
|
414 |
#undef __FUNCT__
|
|
|
415 |
#define __FUNCT__ "EPSPowerGetShiftType"
|
| 707 |
dsic.upv.es!antodo |
416 |
/*@C
|
| 446 |
dsic.upv.es!jroman |
417 |
EPSPowerGetShiftType - Gets the type of shifts used during the power
|
|
|
418 |
iteration.
|
|
|
419 |
|
|
|
420 |
Collective on EPS
|
|
|
421 |
|
|
|
422 |
Input Parameter:
|
|
|
423 |
. eps - the eigenproblem solver context
|
|
|
424 |
|
|
|
425 |
Input Parameter:
|
|
|
426 |
. shift - the type of shift
|
|
|
427 |
|
|
|
428 |
Level: advanced
|
|
|
429 |
|
|
|
430 |
.seealso: EPSSetShiftType()
|
|
|
431 |
@*/
|
| 476 |
dsic.upv.es!antodo |
432 |
PetscErrorCode EPSPowerGetShiftType(EPS eps,EPSPowerShiftType *shift)
|
| 444 |
dsic.upv.es!antodo |
433 |
{
|
| 476 |
dsic.upv.es!antodo |
434 |
PetscErrorCode ierr, (*f)(EPS,EPSPowerShiftType*);
|
| 444 |
dsic.upv.es!antodo |
435 |
|
|
|
436 |
PetscFunctionBegin;
|
|
|
437 |
PetscValidHeaderSpecific(eps,EPS_COOKIE,1);
|
|
|
438 |
ierr = PetscObjectQueryFunction((PetscObject)eps,"EPSPowerGetShiftType_C",(void (**)())&f);CHKERRQ(ierr);
|
|
|
439 |
if (f) {
|
|
|
440 |
ierr = (*f)(eps,shift);CHKERRQ(ierr);
|
|
|
441 |
}
|
|
|
442 |
PetscFunctionReturn(0);
|
|
|
443 |
}
|
|
|
444 |
|
| 450 |
dsic.upv.es!antodo |
445 |
#undef __FUNCT__
|
|
|
446 |
#define __FUNCT__ "EPSView_POWER"
|
| 476 |
dsic.upv.es!antodo |
447 |
PetscErrorCode EPSView_POWER(EPS eps,PetscViewer viewer)
|
| 450 |
dsic.upv.es!antodo |
448 |
{
|
| 476 |
dsic.upv.es!antodo |
449 |
PetscErrorCode ierr;
|
|
|
450 |
EPS_POWER *power = (EPS_POWER *)eps->data;
|
|
|
451 |
PetscTruth isascii;
|
|
|
452 |
const char *shift_list[3] = { "constant", "rayleigh", "wilkinson" };
|
| 450 |
dsic.upv.es!antodo |
453 |
|
|
|
454 |
PetscFunctionBegin;
|
|
|
455 |
ierr = PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&isascii);CHKERRQ(ierr);
|
|
|
456 |
if (!isascii) {
|
|
|
457 |
SETERRQ1(1,"Viewer type %s not supported for EPSPOWER",((PetscObject)viewer)->type_name);
|
|
|
458 |
}
|
|
|
459 |
ierr = PetscViewerASCIIPrintf(viewer,"shift type: %s\n",shift_list[power->shift_type]);CHKERRQ(ierr);
|
|
|
460 |
PetscFunctionReturn(0);
|
|
|
461 |
}
|
|
|
462 |
|
| 444 |
dsic.upv.es!antodo |
463 |
EXTERN_C_BEGIN
|
|
|
464 |
#undef __FUNCT__
|
| 6 |
dsic.upv.es!jroman |
465 |
#define __FUNCT__ "EPSCreate_POWER"
|
| 476 |
dsic.upv.es!antodo |
466 |
PetscErrorCode EPSCreate_POWER(EPS eps)
|
| 6 |
dsic.upv.es!jroman |
467 |
{
|
| 476 |
dsic.upv.es!antodo |
468 |
PetscErrorCode ierr;
|
|
|
469 |
EPS_POWER *power;
|
| 444 |
dsic.upv.es!antodo |
470 |
|
| 6 |
dsic.upv.es!jroman |
471 |
PetscFunctionBegin;
|
| 444 |
dsic.upv.es!antodo |
472 |
ierr = PetscNew(EPS_POWER,&power);CHKERRQ(ierr);
|
|
|
473 |
PetscMemzero(power,sizeof(EPS_POWER));
|
|
|
474 |
PetscLogObjectMemory(eps,sizeof(EPS_POWER));
|
|
|
475 |
eps->data = (void *) power;
|
| 503 |
dsic.upv.es!antodo |
476 |
eps->ops->solve = EPSSolve_POWER;
|
| 780 |
dsic.upv.es!jroman |
477 |
eps->ops->solvets = EPSSolve_TS_POWER;
|
| 503 |
dsic.upv.es!antodo |
478 |
eps->ops->setup = EPSSetUp_POWER;
|
| 444 |
dsic.upv.es!antodo |
479 |
eps->ops->setfromoptions = EPSSetFromOptions_POWER;
|
| 259 |
dsic.upv.es!antodo |
480 |
eps->ops->destroy = EPSDestroy_Default;
|
| 450 |
dsic.upv.es!antodo |
481 |
eps->ops->view = EPSView_POWER;
|
| 444 |
dsic.upv.es!antodo |
482 |
eps->ops->backtransform = EPSBackTransform_POWER;
|
| 503 |
dsic.upv.es!antodo |
483 |
eps->ops->computevectors = EPSComputeVectors_Default;
|
| 444 |
dsic.upv.es!antodo |
484 |
power->shift_type = EPSPOWER_SHIFT_CONSTANT;
|
|
|
485 |
ierr = PetscObjectComposeFunctionDynamic((PetscObject)eps,"EPSPowerSetShiftType_C","EPSPowerSetShiftType_POWER",EPSPowerSetShiftType_POWER);CHKERRQ(ierr);
|
|
|
486 |
ierr = PetscObjectComposeFunctionDynamic((PetscObject)eps,"EPSPowerGetShiftType_C","EPSPowerGetShiftType_POWER",EPSPowerGetShiftType_POWER);CHKERRQ(ierr);
|
| 6 |
dsic.upv.es!jroman |
487 |
PetscFunctionReturn(0);
|
|
|
488 |
}
|
|
|
489 |
EXTERN_C_END
|
| 531 |
dsic.upv.es!jroman |
490 |
|