| 6 |
dsic.upv.es!jroman |
1 |
/*
|
|
|
2 |
The ST (spectral transformation) interface routines, callable by users.
|
| 1376 |
slepc |
3 |
|
|
|
4 |
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
| 1672 |
slepc |
5 |
SLEPc - Scalable Library for Eigenvalue Problem Computations
|
|
|
6 |
Copyright (c) 2002-2009, Universidad Politecnica de Valencia, Spain
|
| 1376 |
slepc |
7 |
|
| 1672 |
slepc |
8 |
This file is part of SLEPc.
|
|
|
9 |
|
|
|
10 |
SLEPc is free software: you can redistribute it and/or modify it under the
|
|
|
11 |
terms of version 3 of the GNU Lesser General Public License as published by
|
|
|
12 |
the Free Software Foundation.
|
|
|
13 |
|
|
|
14 |
SLEPc is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
15 |
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
16 |
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
|
|
|
17 |
more details.
|
|
|
18 |
|
|
|
19 |
You should have received a copy of the GNU Lesser General Public License
|
|
|
20 |
along with SLEPc. If not, see <http://www.gnu.org/licenses/>.
|
| 1376 |
slepc |
21 |
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
| 6 |
dsic.upv.es!jroman |
22 |
*/
|
|
|
23 |
|
| 1521 |
slepc |
24 |
#include "private/stimpl.h" /*I "slepcst.h" I*/
|
| 6 |
dsic.upv.es!jroman |
25 |
|
|
|
26 |
#undef __FUNCT__
|
|
|
27 |
#define __FUNCT__ "STApply"
|
|
|
28 |
/*@
|
|
|
29 |
STApply - Applies the spectral transformation operator to a vector, for
|
|
|
30 |
instance (A - sB)^-1 B in the case of the shift-and-invert tranformation
|
|
|
31 |
and generalized eigenproblem.
|
|
|
32 |
|
|
|
33 |
Collective on ST and Vec
|
|
|
34 |
|
|
|
35 |
Input Parameters:
|
|
|
36 |
+ st - the spectral transformation context
|
|
|
37 |
- x - input vector
|
|
|
38 |
|
|
|
39 |
Output Parameter:
|
|
|
40 |
. y - output vector
|
|
|
41 |
|
|
|
42 |
Level: developer
|
|
|
43 |
|
| 1358 |
slepc |
44 |
.seealso: STApplyTranspose()
|
| 6 |
dsic.upv.es!jroman |
45 |
@*/
|
| 476 |
dsic.upv.es!antodo |
46 |
PetscErrorCode STApply(ST st,Vec x,Vec y)
|
| 6 |
dsic.upv.es!jroman |
47 |
{
|
| 476 |
dsic.upv.es!antodo |
48 |
PetscErrorCode ierr;
|
| 6 |
dsic.upv.es!jroman |
49 |
|
|
|
50 |
PetscFunctionBegin;
|
| 25 |
dsic.upv.es!jroman |
51 |
PetscValidHeaderSpecific(st,ST_COOKIE,1);
|
|
|
52 |
PetscValidHeaderSpecific(x,VEC_COOKIE,2);
|
|
|
53 |
PetscValidHeaderSpecific(y,VEC_COOKIE,3);
|
| 6 |
dsic.upv.es!jroman |
54 |
if (x == y) SETERRQ(PETSC_ERR_ARG_IDN,"x and y must be different vectors");
|
|
|
55 |
|
|
|
56 |
if (!st->setupcalled) { ierr = STSetUp(st); CHKERRQ(ierr); }
|
|
|
57 |
|
|
|
58 |
ierr = PetscLogEventBegin(ST_Apply,st,x,y,0);CHKERRQ(ierr);
|
| 1209 |
slepc |
59 |
st->applys++;
|
| 6 |
dsic.upv.es!jroman |
60 |
ierr = (*st->ops->apply)(st,x,y);CHKERRQ(ierr);
|
|
|
61 |
ierr = PetscLogEventEnd(ST_Apply,st,x,y,0);CHKERRQ(ierr);
|
|
|
62 |
PetscFunctionReturn(0);
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
#undef __FUNCT__
|
| 1358 |
slepc |
66 |
#define __FUNCT__ "STGetBilinearForm"
|
| 6 |
dsic.upv.es!jroman |
67 |
/*@
|
| 1358 |
slepc |
68 |
STGetBilinearForm - Returns the matrix used in the bilinear form with a semi-definite generalised problem.
|
| 6 |
dsic.upv.es!jroman |
69 |
|
| 1358 |
slepc |
70 |
Collective on ST and Mat
|
| 6 |
dsic.upv.es!jroman |
71 |
|
|
|
72 |
Input Parameters:
|
| 1358 |
slepc |
73 |
. st - the spectral transformation context
|
| 6 |
dsic.upv.es!jroman |
74 |
|
|
|
75 |
Output Parameter:
|
| 1358 |
slepc |
76 |
. B - output matrix
|
| 6 |
dsic.upv.es!jroman |
77 |
|
| 1449 |
slepc |
78 |
Note:
|
|
|
79 |
The output matrix B must be destroyed after use.
|
|
|
80 |
|
| 6 |
dsic.upv.es!jroman |
81 |
Level: developer
|
|
|
82 |
@*/
|
| 1358 |
slepc |
83 |
PetscErrorCode STGetBilinearForm(ST st,Mat *B)
|
| 6 |
dsic.upv.es!jroman |
84 |
{
|
| 476 |
dsic.upv.es!antodo |
85 |
PetscErrorCode ierr;
|
| 6 |
dsic.upv.es!jroman |
86 |
|
|
|
87 |
PetscFunctionBegin;
|
| 25 |
dsic.upv.es!jroman |
88 |
PetscValidHeaderSpecific(st,ST_COOKIE,1);
|
| 1358 |
slepc |
89 |
PetscValidPointer(B,2);
|
|
|
90 |
ierr = (*st->ops->getbilinearform)(st,B);CHKERRQ(ierr);
|
| 6 |
dsic.upv.es!jroman |
91 |
PetscFunctionReturn(0);
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
#undef __FUNCT__
|
| 1358 |
slepc |
95 |
#define __FUNCT__ "STGetBilinearForm_Default"
|
|
|
96 |
PetscErrorCode STGetBilinearForm_Default(ST st,Mat *B)
|
| 6 |
dsic.upv.es!jroman |
97 |
{
|
| 1450 |
slepc |
98 |
PetscErrorCode ierr;
|
|
|
99 |
|
| 6 |
dsic.upv.es!jroman |
100 |
PetscFunctionBegin;
|
| 1358 |
slepc |
101 |
*B = st->B;
|
| 1449 |
slepc |
102 |
if (*B) {
|
|
|
103 |
ierr = PetscObjectReference((PetscObject)*B);CHKERRQ(ierr);
|
|
|
104 |
}
|
| 6 |
dsic.upv.es!jroman |
105 |
PetscFunctionReturn(0);
|
|
|
106 |
}
|
|
|
107 |
|
|
|
108 |
#undef __FUNCT__
|
| 780 |
dsic.upv.es!jroman |
109 |
#define __FUNCT__ "STApplyTranspose"
|
|
|
110 |
/*@
|
|
|
111 |
STApplyTranspose - Applies the transpose of the operator to a vector, for
|
|
|
112 |
instance B^T(A - sB)^-T in the case of the shift-and-invert tranformation
|
|
|
113 |
and generalized eigenproblem.
|
|
|
114 |
|
|
|
115 |
Collective on ST and Vec
|
|
|
116 |
|
|
|
117 |
Input Parameters:
|
|
|
118 |
+ st - the spectral transformation context
|
|
|
119 |
- x - input vector
|
|
|
120 |
|
|
|
121 |
Output Parameter:
|
|
|
122 |
. y - output vector
|
|
|
123 |
|
|
|
124 |
Level: developer
|
|
|
125 |
|
|
|
126 |
.seealso: STApply()
|
|
|
127 |
@*/
|
|
|
128 |
PetscErrorCode STApplyTranspose(ST st,Vec x,Vec y)
|
|
|
129 |
{
|
|
|
130 |
PetscErrorCode ierr;
|
|
|
131 |
|
|
|
132 |
PetscFunctionBegin;
|
|
|
133 |
PetscValidHeaderSpecific(st,ST_COOKIE,1);
|
|
|
134 |
PetscValidHeaderSpecific(x,VEC_COOKIE,2);
|
|
|
135 |
PetscValidHeaderSpecific(y,VEC_COOKIE,3);
|
|
|
136 |
if (x == y) SETERRQ(PETSC_ERR_ARG_IDN,"x and y must be different vectors");
|
|
|
137 |
|
|
|
138 |
if (!st->setupcalled) { ierr = STSetUp(st); CHKERRQ(ierr); }
|
|
|
139 |
|
|
|
140 |
ierr = PetscLogEventBegin(ST_ApplyTranspose,st,x,y,0);CHKERRQ(ierr);
|
|
|
141 |
ierr = (*st->ops->applytrans)(st,x,y);CHKERRQ(ierr);
|
|
|
142 |
ierr = PetscLogEventEnd(ST_ApplyTranspose,st,x,y,0);CHKERRQ(ierr);
|
|
|
143 |
PetscFunctionReturn(0);
|
|
|
144 |
}
|
|
|
145 |
|
|
|
146 |
#undef __FUNCT__
|
| 677 |
dsic.upv.es!antodo |
147 |
#define __FUNCT__ "STComputeExplicitOperator"
|
|
|
148 |
/*@
|
|
|
149 |
STComputeExplicitOperator - Computes the explicit operator associated
|
|
|
150 |
to the eigenvalue problem with the specified spectral transformation.
|
|
|
151 |
|
| 683 |
dsic.upv.es!jroman |
152 |
Collective on ST
|
| 677 |
dsic.upv.es!antodo |
153 |
|
|
|
154 |
Input Parameter:
|
| 683 |
dsic.upv.es!jroman |
155 |
. st - the spectral transform context
|
| 677 |
dsic.upv.es!antodo |
156 |
|
|
|
157 |
Output Parameter:
|
|
|
158 |
. mat - the explicit operator
|
|
|
159 |
|
|
|
160 |
Notes:
|
|
|
161 |
This routine builds a matrix containing the explicit operator. For
|
|
|
162 |
example, in generalized problems with shift-and-invert spectral
|
|
|
163 |
transformation the result would be matrix (A - s B)^-1 B.
|
|
|
164 |
|
|
|
165 |
This computation is done by applying the operator to columns of the
|
| 683 |
dsic.upv.es!jroman |
166 |
identity matrix. Note that the result is a dense matrix.
|
| 677 |
dsic.upv.es!antodo |
167 |
|
|
|
168 |
Level: advanced
|
|
|
169 |
|
|
|
170 |
.seealso: STApply()
|
|
|
171 |
@*/
|
|
|
172 |
PetscErrorCode STComputeExplicitOperator(ST st,Mat *mat)
|
|
|
173 |
{
|
|
|
174 |
PetscErrorCode ierr;
|
|
|
175 |
Vec in,out;
|
| 982 |
slepc |
176 |
PetscInt i,M,m,*rows,start,end;
|
| 828 |
dsic.upv.es!antodo |
177 |
PetscScalar *array,one = 1.0;
|
| 677 |
dsic.upv.es!antodo |
178 |
|
|
|
179 |
PetscFunctionBegin;
|
|
|
180 |
PetscValidHeaderSpecific(st,ST_COOKIE,1);
|
|
|
181 |
PetscValidPointer(mat,2);
|
|
|
182 |
|
|
|
183 |
ierr = MatGetVecs(st->A,&in,&out);CHKERRQ(ierr);
|
|
|
184 |
ierr = VecGetSize(out,&M);CHKERRQ(ierr);
|
|
|
185 |
ierr = VecGetLocalSize(out,&m);CHKERRQ(ierr);
|
|
|
186 |
ierr = VecGetOwnershipRange(out,&start,&end);CHKERRQ(ierr);
|
| 1508 |
slepc |
187 |
ierr = PetscMalloc(m*sizeof(PetscInt),&rows);CHKERRQ(ierr);
|
| 677 |
dsic.upv.es!antodo |
188 |
for (i=0; i<m; i++) rows[i] = start + i;
|
|
|
189 |
|
| 1422 |
slepc |
190 |
ierr = MatCreateMPIDense(((PetscObject)st)->comm,m,m,M,M,PETSC_NULL,mat);CHKERRQ(ierr);
|
| 677 |
dsic.upv.es!antodo |
191 |
|
|
|
192 |
for (i=0; i<M; i++) {
|
| 828 |
dsic.upv.es!antodo |
193 |
ierr = VecSet(in,0.0);CHKERRQ(ierr);
|
| 677 |
dsic.upv.es!antodo |
194 |
ierr = VecSetValues(in,1,&i,&one,INSERT_VALUES);CHKERRQ(ierr);
|
|
|
195 |
ierr = VecAssemblyBegin(in);CHKERRQ(ierr);
|
|
|
196 |
ierr = VecAssemblyEnd(in);CHKERRQ(ierr);
|
|
|
197 |
|
|
|
198 |
ierr = STApply(st,in,out); CHKERRQ(ierr);
|
|
|
199 |
|
|
|
200 |
ierr = VecGetArray(out,&array);CHKERRQ(ierr);
|
|
|
201 |
ierr = MatSetValues(*mat,m,rows,1,&i,array,INSERT_VALUES);CHKERRQ(ierr);
|
|
|
202 |
ierr = VecRestoreArray(out,&array);CHKERRQ(ierr);
|
|
|
203 |
}
|
|
|
204 |
ierr = PetscFree(rows);CHKERRQ(ierr);
|
|
|
205 |
ierr = VecDestroy(in);CHKERRQ(ierr);
|
|
|
206 |
ierr = VecDestroy(out);CHKERRQ(ierr);
|
|
|
207 |
ierr = MatAssemblyBegin(*mat,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
|
|
|
208 |
ierr = MatAssemblyEnd(*mat,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
|
|
|
209 |
PetscFunctionReturn(0);
|
|
|
210 |
}
|
|
|
211 |
|
|
|
212 |
#undef __FUNCT__
|
| 6 |
dsic.upv.es!jroman |
213 |
#define __FUNCT__ "STSetUp"
|
|
|
214 |
/*@
|
|
|
215 |
STSetUp - Prepares for the use of a spectral transformation.
|
|
|
216 |
|
|
|
217 |
Collective on ST
|
|
|
218 |
|
|
|
219 |
Input Parameter:
|
|
|
220 |
. st - the spectral transformation context
|
|
|
221 |
|
|
|
222 |
Level: advanced
|
|
|
223 |
|
|
|
224 |
.seealso: STCreate(), STApply(), STDestroy()
|
|
|
225 |
@*/
|
| 476 |
dsic.upv.es!antodo |
226 |
PetscErrorCode STSetUp(ST st)
|
| 6 |
dsic.upv.es!jroman |
227 |
{
|
| 476 |
dsic.upv.es!antodo |
228 |
PetscErrorCode ierr;
|
| 6 |
dsic.upv.es!jroman |
229 |
|
|
|
230 |
PetscFunctionBegin;
|
| 25 |
dsic.upv.es!jroman |
231 |
PetscValidHeaderSpecific(st,ST_COOKIE,1);
|
| 6 |
dsic.upv.es!jroman |
232 |
|
| 1038 |
slepc |
233 |
PetscInfo(st,"Setting up new ST\n");
|
| 6 |
dsic.upv.es!jroman |
234 |
if (st->setupcalled) PetscFunctionReturn(0);
|
|
|
235 |
ierr = PetscLogEventBegin(ST_SetUp,st,0,0,0);CHKERRQ(ierr);
|
|
|
236 |
if (!st->A) {SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Matrix must be set first");}
|
| 1422 |
slepc |
237 |
if (!((PetscObject)st)->type_name) {
|
| 106 |
dsic.upv.es!antodo |
238 |
ierr = STSetType(st,STSHIFT);CHKERRQ(ierr);
|
| 6 |
dsic.upv.es!jroman |
239 |
}
|
| 415 |
dsic.upv.es!antodo |
240 |
if (st->w) { ierr = VecDestroy(st->w);CHKERRQ(ierr); }
|
| 1358 |
slepc |
241 |
ierr = MatGetVecs(st->A,&st->w,PETSC_NULL);CHKERRQ(ierr);
|
| 6 |
dsic.upv.es!jroman |
242 |
if (st->ops->setup) {
|
|
|
243 |
ierr = (*st->ops->setup)(st); CHKERRQ(ierr);
|
|
|
244 |
}
|
|
|
245 |
st->setupcalled = 1;
|
|
|
246 |
ierr = PetscLogEventEnd(ST_SetUp,st,0,0,0);CHKERRQ(ierr);
|
|
|
247 |
PetscFunctionReturn(0);
|
|
|
248 |
}
|
|
|
249 |
|
|
|
250 |
#undef __FUNCT__
|
|
|
251 |
#define __FUNCT__ "STPostSolve"
|
| 1029 |
slepc |
252 |
/*@
|
| 6 |
dsic.upv.es!jroman |
253 |
STPostSolve - Optional post-solve phase, intended for any actions that must
|
|
|
254 |
be performed on the ST object after the eigensolver has finished.
|
|
|
255 |
|
|
|
256 |
Collective on ST
|
|
|
257 |
|
|
|
258 |
Input Parameters:
|
| 1029 |
slepc |
259 |
. st - the spectral transformation context
|
| 6 |
dsic.upv.es!jroman |
260 |
|
| 1029 |
slepc |
261 |
Level: developer
|
| 6 |
dsic.upv.es!jroman |
262 |
|
| 1029 |
slepc |
263 |
.seealso: EPSSolve()
|
|
|
264 |
@*/
|
|
|
265 |
PetscErrorCode STPostSolve(ST st)
|
| 6 |
dsic.upv.es!jroman |
266 |
{
|
| 476 |
dsic.upv.es!antodo |
267 |
PetscErrorCode ierr;
|
| 6 |
dsic.upv.es!jroman |
268 |
|
|
|
269 |
PetscFunctionBegin;
|
| 25 |
dsic.upv.es!jroman |
270 |
PetscValidHeaderSpecific(st,ST_COOKIE,1);
|
| 6 |
dsic.upv.es!jroman |
271 |
if (st->ops->postsolve) {
|
|
|
272 |
ierr = (*st->ops->postsolve)(st);CHKERRQ(ierr);
|
|
|
273 |
}
|
|
|
274 |
|
|
|
275 |
PetscFunctionReturn(0);
|
|
|
276 |
}
|
|
|
277 |
|
|
|
278 |
#undef __FUNCT__
|
|
|
279 |
#define __FUNCT__ "STBackTransform"
|
| 531 |
dsic.upv.es!jroman |
280 |
/*@
|
|
|
281 |
STBackTransform - Back-transformation phase, intended for
|
|
|
282 |
spectral transformations which require to transform the computed
|
| 6 |
dsic.upv.es!jroman |
283 |
eigenvalues back to the original eigenvalue problem.
|
|
|
284 |
|
|
|
285 |
Collective on ST
|
|
|
286 |
|
|
|
287 |
Input Parameters:
|
|
|
288 |
st - the spectral transformation context
|
|
|
289 |
eigr - real part of a computed eigenvalue
|
|
|
290 |
eigi - imaginary part of a computed eigenvalue
|
|
|
291 |
|
|
|
292 |
Level: developer
|
|
|
293 |
|
|
|
294 |
.seealso: EPSBackTransform()
|
| 540 |
dsic.upv.es!jroman |
295 |
@*/
|
| 476 |
dsic.upv.es!antodo |
296 |
PetscErrorCode STBackTransform(ST st,PetscScalar* eigr,PetscScalar* eigi)
|
| 6 |
dsic.upv.es!jroman |
297 |
{
|
| 476 |
dsic.upv.es!antodo |
298 |
PetscErrorCode ierr;
|
| 6 |
dsic.upv.es!jroman |
299 |
|
|
|
300 |
PetscFunctionBegin;
|
| 25 |
dsic.upv.es!jroman |
301 |
PetscValidHeaderSpecific(st,ST_COOKIE,1);
|
| 6 |
dsic.upv.es!jroman |
302 |
if (st->ops->backtr) {
|
|
|
303 |
ierr = (*st->ops->backtr)(st,eigr,eigi);CHKERRQ(ierr);
|
|
|
304 |
}
|
|
|
305 |
|
|
|
306 |
PetscFunctionReturn(0);
|
|
|
307 |
}
|