| 6 |
dsic.upv.es!jroman |
1 |
/*
|
|
|
2 |
Routines to set ST methods and options.
|
| 1376 |
slepc |
3 |
|
|
|
4 |
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
| 1672 |
slepc |
5 |
SLEPc - Scalable Library for Eigenvalue Problem Computations
|
| 2575 |
eromero |
6 |
Copyright (c) 2002-2011, Universitat 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 |
|
| 2283 |
jroman |
24 |
#include <private/stimpl.h> /*I "slepcst.h" I*/
|
| 6 |
dsic.upv.es!jroman |
25 |
|
| 2376 |
jroman |
26 |
PetscBool STRegisterAllCalled = PETSC_FALSE;
|
| 6 |
dsic.upv.es!jroman |
27 |
PetscFList STList = 0;
|
|
|
28 |
|
|
|
29 |
#undef __FUNCT__
|
|
|
30 |
#define __FUNCT__ "STSetType"
|
|
|
31 |
/*@C
|
|
|
32 |
STSetType - Builds ST for a particular spectral transformation.
|
|
|
33 |
|
| 2328 |
jroman |
34 |
Logically Collective on ST
|
| 6 |
dsic.upv.es!jroman |
35 |
|
|
|
36 |
Input Parameter:
|
|
|
37 |
+ st - the spectral transformation context.
|
|
|
38 |
- type - a known type
|
|
|
39 |
|
|
|
40 |
Options Database Key:
|
|
|
41 |
. -st_type <type> - Sets ST type
|
|
|
42 |
|
| 172 |
dsic.upv.es!jroman |
43 |
Use -help for a list of available transformations
|
| 6 |
dsic.upv.es!jroman |
44 |
|
|
|
45 |
Notes:
|
| 172 |
dsic.upv.es!jroman |
46 |
See "slepc/include/slepcst.h" for available transformations
|
| 6 |
dsic.upv.es!jroman |
47 |
|
|
|
48 |
Normally, it is best to use the EPSSetFromOptions() command and
|
|
|
49 |
then set the ST type from the options database rather than by using
|
|
|
50 |
this routine. Using the options database provides the user with
|
|
|
51 |
maximum flexibility in evaluating the many different transformations.
|
|
|
52 |
|
|
|
53 |
Level: intermediate
|
|
|
54 |
|
|
|
55 |
.seealso: EPSSetType()
|
|
|
56 |
|
|
|
57 |
@*/
|
| 1502 |
slepc |
58 |
PetscErrorCode STSetType(ST st,const STType type)
|
| 6 |
dsic.upv.es!jroman |
59 |
{
|
| 476 |
dsic.upv.es!antodo |
60 |
PetscErrorCode ierr,(*r)(ST);
|
| 2216 |
jroman |
61 |
PetscBool match;
|
| 6 |
dsic.upv.es!jroman |
62 |
|
|
|
63 |
PetscFunctionBegin;
|
| 2213 |
jroman |
64 |
PetscValidHeaderSpecific(st,ST_CLASSID,1);
|
| 25 |
dsic.upv.es!jroman |
65 |
PetscValidCharPointer(type,2);
|
| 6 |
dsic.upv.es!jroman |
66 |
|
|
|
67 |
ierr = PetscTypeCompare((PetscObject)st,type,&match);CHKERRQ(ierr);
|
|
|
68 |
if (match) PetscFunctionReturn(0);
|
|
|
69 |
|
| 2348 |
jroman |
70 |
ierr = PetscFListFind(STList,((PetscObject)st)->comm,type,PETSC_TRUE,(void (**)(void))&r);CHKERRQ(ierr);
|
|
|
71 |
if (!r) SETERRQ1(((PetscObject)st)->comm,PETSC_ERR_ARG_UNKNOWN_TYPE,"Unable to find requested ST type %s",type);
|
| 6 |
dsic.upv.es!jroman |
72 |
|
| 2348 |
jroman |
73 |
if (st->ops->destroy) { ierr = (*st->ops->destroy)(st);CHKERRQ(ierr); }
|
| 337 |
dsic.upv.es!antodo |
74 |
ierr = PetscMemzero(st->ops,sizeof(struct _STOps));CHKERRQ(ierr);
|
| 6 |
dsic.upv.es!jroman |
75 |
|
| 2348 |
jroman |
76 |
st->setupcalled = 0;
|
| 6 |
dsic.upv.es!jroman |
77 |
ierr = PetscObjectChangeTypeName((PetscObject)st,type);CHKERRQ(ierr);
|
| 2348 |
jroman |
78 |
ierr = (*r)(st);CHKERRQ(ierr);
|
| 6 |
dsic.upv.es!jroman |
79 |
PetscFunctionReturn(0);
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
#undef __FUNCT__
|
|
|
83 |
#define __FUNCT__ "STGetType"
|
|
|
84 |
/*@C
|
| 172 |
dsic.upv.es!jroman |
85 |
STGetType - Gets the ST type name (as a string) from the ST context.
|
| 6 |
dsic.upv.es!jroman |
86 |
|
|
|
87 |
Not Collective
|
|
|
88 |
|
|
|
89 |
Input Parameter:
|
|
|
90 |
. st - the spectral transformation context
|
|
|
91 |
|
|
|
92 |
Output Parameter:
|
|
|
93 |
. name - name of the spectral transformation
|
|
|
94 |
|
|
|
95 |
Level: intermediate
|
|
|
96 |
|
|
|
97 |
.seealso: STSetType()
|
|
|
98 |
|
|
|
99 |
@*/
|
| 1501 |
slepc |
100 |
PetscErrorCode STGetType(ST st,const STType *type)
|
| 6 |
dsic.upv.es!jroman |
101 |
{
|
|
|
102 |
PetscFunctionBegin;
|
| 2213 |
jroman |
103 |
PetscValidHeaderSpecific(st,ST_CLASSID,1);
|
| 1501 |
slepc |
104 |
PetscValidPointer(type,2);
|
|
|
105 |
*type = ((PetscObject)st)->type_name;
|
| 6 |
dsic.upv.es!jroman |
106 |
PetscFunctionReturn(0);
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
#undef __FUNCT__
|
|
|
110 |
#define __FUNCT__ "STSetFromOptions"
|
|
|
111 |
/*@
|
|
|
112 |
STSetFromOptions - Sets ST options from the options database.
|
|
|
113 |
This routine must be called before STSetUp() if the user is to be
|
|
|
114 |
allowed to set the type of transformation.
|
|
|
115 |
|
|
|
116 |
Collective on ST
|
|
|
117 |
|
|
|
118 |
Input Parameter:
|
|
|
119 |
. st - the spectral transformation context
|
|
|
120 |
|
|
|
121 |
Level: beginner
|
|
|
122 |
|
|
|
123 |
.seealso:
|
|
|
124 |
|
|
|
125 |
@*/
|
| 476 |
dsic.upv.es!antodo |
126 |
PetscErrorCode STSetFromOptions(ST st)
|
| 6 |
dsic.upv.es!jroman |
127 |
{
|
| 476 |
dsic.upv.es!antodo |
128 |
PetscErrorCode ierr;
|
| 982 |
slepc |
129 |
PetscInt i;
|
| 2074 |
jroman |
130 |
PetscScalar s;
|
| 476 |
dsic.upv.es!antodo |
131 |
char type[256];
|
| 2216 |
jroman |
132 |
PetscBool flg;
|
| 2331 |
jroman |
133 |
const char *mode_list[3] = {"copy","inplace","shell"};
|
|
|
134 |
const char *structure_list[3] = {"same","different","subset"};
|
| 6 |
dsic.upv.es!jroman |
135 |
|
|
|
136 |
PetscFunctionBegin;
|
| 2213 |
jroman |
137 |
PetscValidHeaderSpecific(st,ST_CLASSID,1);
|
| 2376 |
jroman |
138 |
if (!STRegisterAllCalled) { ierr = STRegisterAll(PETSC_NULL);CHKERRQ(ierr); }
|
| 1422 |
slepc |
139 |
ierr = PetscOptionsBegin(((PetscObject)st)->comm,((PetscObject)st)->prefix,"Spectral Transformation (ST) Options","ST");CHKERRQ(ierr);
|
|
|
140 |
ierr = PetscOptionsList("-st_type","Spectral Transformation type","STSetType",STList,(char*)(((PetscObject)st)->type_name?((PetscObject)st)->type_name:STSHIFT),type,256,&flg);CHKERRQ(ierr);
|
| 6 |
dsic.upv.es!jroman |
141 |
if (flg) {
|
|
|
142 |
ierr = STSetType(st,type);CHKERRQ(ierr);
|
|
|
143 |
}
|
|
|
144 |
/*
|
|
|
145 |
Set the type if it was never set.
|
|
|
146 |
*/
|
| 1422 |
slepc |
147 |
if (!((PetscObject)st)->type_name) {
|
| 106 |
dsic.upv.es!antodo |
148 |
ierr = STSetType(st,STSHIFT);CHKERRQ(ierr);
|
| 6 |
dsic.upv.es!jroman |
149 |
}
|
|
|
150 |
|
| 2074 |
jroman |
151 |
ierr = PetscOptionsScalar("-st_shift","Value of the shift","STSetShift",st->sigma,&s,&flg);CHKERRQ(ierr);
|
|
|
152 |
if (flg) { ierr = STSetShift(st,s);CHKERRQ(ierr); }
|
| 6 |
dsic.upv.es!jroman |
153 |
|
| 2331 |
jroman |
154 |
ierr = PetscOptionsEList("-st_matmode","Shift matrix mode","STSetMatMode",mode_list,3,mode_list[st->shift_matrix],&i,&flg);CHKERRQ(ierr);
|
| 356 |
dsic.upv.es!antodo |
155 |
if (flg) { st->shift_matrix = (STMatMode)i; }
|
| 344 |
dsic.upv.es!antodo |
156 |
|
| 2331 |
jroman |
157 |
ierr = PetscOptionsEList("-st_matstructure","Shift nonzero pattern","STSetMatStructure",structure_list,3,structure_list[st->str],&i,&flg);CHKERRQ(ierr);
|
| 2446 |
jroman |
158 |
if (flg) {
|
|
|
159 |
switch (i) {
|
|
|
160 |
case 0: ierr = STSetMatStructure(st,SAME_NONZERO_PATTERN);CHKERRQ(ierr); break;
|
|
|
161 |
case 1: ierr = STSetMatStructure(st,DIFFERENT_NONZERO_PATTERN);CHKERRQ(ierr); break;
|
|
|
162 |
case 2: ierr = STSetMatStructure(st,SUBSET_NONZERO_PATTERN);CHKERRQ(ierr); break;
|
|
|
163 |
}
|
|
|
164 |
}
|
| 344 |
dsic.upv.es!antodo |
165 |
|
| 6 |
dsic.upv.es!jroman |
166 |
if (st->ops->setfromoptions) {
|
|
|
167 |
ierr = (*st->ops->setfromoptions)(st);CHKERRQ(ierr);
|
|
|
168 |
}
|
| 2384 |
jroman |
169 |
ierr = PetscObjectProcessOptionsHandlers((PetscObject)st);CHKERRQ(ierr);
|
| 6 |
dsic.upv.es!jroman |
170 |
ierr = PetscOptionsEnd();CHKERRQ(ierr);
|
| 2005 |
eromero |
171 |
ierr = KSPSetFromOptions(st->ksp);CHKERRQ(ierr);
|
| 6 |
dsic.upv.es!jroman |
172 |
PetscFunctionReturn(0);
|
|
|
173 |
}
|
|
|
174 |
|
| 344 |
dsic.upv.es!antodo |
175 |
#undef __FUNCT__
|
|
|
176 |
#define __FUNCT__ "STSetMatStructure"
|
|
|
177 |
/*@
|
|
|
178 |
STSetMatStructure - Sets an internal MatStructure attribute to
|
|
|
179 |
indicate which is the relation of the sparsity pattern of the two matrices
|
| 2328 |
jroman |
180 |
A and B constituting the generalized eigenvalue problem.
|
| 344 |
dsic.upv.es!antodo |
181 |
|
| 2328 |
jroman |
182 |
Logically Collective on ST
|
| 344 |
dsic.upv.es!antodo |
183 |
|
|
|
184 |
Input Parameters:
|
|
|
185 |
+ st - the spectral transformation context
|
|
|
186 |
- str - either SAME_NONZERO_PATTERN, DIFFERENT_NONZERO_PATTERN or
|
|
|
187 |
SUBSET_NONZERO_PATTERN
|
|
|
188 |
|
|
|
189 |
Options Database Key:
|
| 354 |
dsic.upv.es!jroman |
190 |
. -st_matstructure <str> - Indicates the structure flag, where <str> is one
|
|
|
191 |
of 'same' (A and B have the same nonzero pattern), 'different' (A
|
| 2316 |
jroman |
192 |
and B have different nonzero pattern) or 'subset' (B's nonzero
|
|
|
193 |
pattern is a subset of A's).
|
| 344 |
dsic.upv.es!antodo |
194 |
|
| 2328 |
jroman |
195 |
Notes:
|
| 344 |
dsic.upv.es!antodo |
196 |
By default, the sparsity patterns are assumed to be different. If the
|
|
|
197 |
patterns are equal or a subset then it is recommended to set this attribute
|
|
|
198 |
for efficiency reasons (in particular, for internal MatAXPY() operations).
|
| 2328 |
jroman |
199 |
|
|
|
200 |
This function has no effect in the case of standard eigenproblems.
|
| 344 |
dsic.upv.es!antodo |
201 |
|
|
|
202 |
Level: advanced
|
|
|
203 |
|
|
|
204 |
.seealso: STSetOperators(), MatAXPY()
|
|
|
205 |
@*/
|
| 476 |
dsic.upv.es!antodo |
206 |
PetscErrorCode STSetMatStructure(ST st,MatStructure str)
|
| 344 |
dsic.upv.es!antodo |
207 |
{
|
|
|
208 |
PetscFunctionBegin;
|
| 2213 |
jroman |
209 |
PetscValidHeaderSpecific(st,ST_CLASSID,1);
|
| 2326 |
jroman |
210 |
PetscValidLogicalCollectiveEnum(st,str,2);
|
| 1241 |
slepc |
211 |
switch (str) {
|
|
|
212 |
case SAME_NONZERO_PATTERN:
|
|
|
213 |
case DIFFERENT_NONZERO_PATTERN:
|
|
|
214 |
case SUBSET_NONZERO_PATTERN:
|
|
|
215 |
st->str = str;
|
|
|
216 |
break;
|
|
|
217 |
default:
|
| 2214 |
jroman |
218 |
SETERRQ(((PetscObject)st)->comm,PETSC_ERR_ARG_OUTOFRANGE,"Invalid matrix structure flag");
|
| 1241 |
slepc |
219 |
}
|
| 344 |
dsic.upv.es!antodo |
220 |
PetscFunctionReturn(0);
|
|
|
221 |
}
|
|
|
222 |
|
|
|
223 |
#undef __FUNCT__
|
| 2107 |
eromero |
224 |
#define __FUNCT__ "STGetMatStructure"
|
|
|
225 |
/*@
|
|
|
226 |
STGetMatStructure - Gets the internal MatStructure attribute to
|
|
|
227 |
indicate which is the relation of the sparsity pattern of the two matrices
|
| 2328 |
jroman |
228 |
A and B constituting the generalized eigenvalue problem.
|
| 2107 |
eromero |
229 |
|
| 2328 |
jroman |
230 |
Not Collective
|
| 2107 |
eromero |
231 |
|
|
|
232 |
Input Parameters:
|
|
|
233 |
. st - the spectral transformation context
|
|
|
234 |
|
|
|
235 |
Output Parameters:
|
|
|
236 |
. str - either SAME_NONZERO_PATTERN, DIFFERENT_NONZERO_PATTERN or
|
|
|
237 |
SUBSET_NONZERO_PATTERN
|
|
|
238 |
|
| 2328 |
jroman |
239 |
Note:
|
|
|
240 |
This function has no effect in the case of standard eigenproblems.
|
|
|
241 |
|
| 2107 |
eromero |
242 |
Level: advanced
|
|
|
243 |
|
|
|
244 |
.seealso: STSetMatStructure(), STSetOperators(), MatAXPY()
|
|
|
245 |
@*/
|
|
|
246 |
PetscErrorCode STGetMatStructure(ST st,MatStructure *str)
|
|
|
247 |
{
|
|
|
248 |
PetscFunctionBegin;
|
| 2213 |
jroman |
249 |
PetscValidHeaderSpecific(st,ST_CLASSID,1);
|
| 2107 |
eromero |
250 |
PetscValidPointer(str,2);
|
|
|
251 |
*str = st->str;
|
|
|
252 |
PetscFunctionReturn(0);
|
|
|
253 |
}
|
|
|
254 |
|
|
|
255 |
#undef __FUNCT__
|
| 344 |
dsic.upv.es!antodo |
256 |
#define __FUNCT__ "STSetMatMode"
|
|
|
257 |
/*@
|
|
|
258 |
STSetMatMode - Sets a flag to indicate how the matrix is
|
|
|
259 |
being shifted in the shift-and-invert and Cayley spectral transformations.
|
|
|
260 |
|
| 2328 |
jroman |
261 |
Logically Collective on ST
|
| 344 |
dsic.upv.es!antodo |
262 |
|
|
|
263 |
Input Parameters:
|
|
|
264 |
+ st - the spectral transformation context
|
| 1940 |
jroman |
265 |
- mode - the mode flag, one of ST_MATMODE_COPY,
|
|
|
266 |
ST_MATMODE_INPLACE or ST_MATMODE_SHELL
|
| 344 |
dsic.upv.es!antodo |
267 |
|
|
|
268 |
Options Database Key:
|
| 354 |
dsic.upv.es!jroman |
269 |
. -st_matmode <mode> - Indicates the mode flag, where <mode> is one of
|
|
|
270 |
'copy', 'inplace' or 'shell' (see explanation below).
|
| 344 |
dsic.upv.es!antodo |
271 |
|
| 354 |
dsic.upv.es!jroman |
272 |
Notes:
|
| 1940 |
jroman |
273 |
By default (ST_MATMODE_COPY), a copy of matrix A is made and then
|
| 344 |
dsic.upv.es!antodo |
274 |
this copy is shifted explicitly, e.g. A <- (A - s B).
|
|
|
275 |
|
| 1940 |
jroman |
276 |
With ST_MATMODE_INPLACE, the original matrix A is shifted at
|
| 344 |
dsic.upv.es!antodo |
277 |
STSetUp() and unshifted at the end of the computations. With respect to
|
|
|
278 |
the previous one, this mode avoids a copy of matrix A. However, a
|
|
|
279 |
backdraw is that the recovered matrix might be slightly different
|
|
|
280 |
from the original one (due to roundoff).
|
|
|
281 |
|
| 1940 |
jroman |
282 |
With ST_MATMODE_SHELL, the solver works with an implicit shell
|
| 344 |
dsic.upv.es!antodo |
283 |
matrix that represents the shifted matrix. This mode is the most efficient
|
|
|
284 |
in creating the shifted matrix but it places serious limitations to the
|
|
|
285 |
linear solves performed in each iteration of the eigensolver (typically,
|
|
|
286 |
only interative solvers with Jacobi preconditioning can be used).
|
|
|
287 |
|
|
|
288 |
In the case of generalized problems, in the two first modes the matrix
|
|
|
289 |
A - s B has to be computed explicitly. The efficiency of this computation
|
| 354 |
dsic.upv.es!jroman |
290 |
can be controlled with STSetMatStructure().
|
| 344 |
dsic.upv.es!antodo |
291 |
|
|
|
292 |
Level: intermediate
|
|
|
293 |
|
| 1364 |
slepc |
294 |
.seealso: STSetOperators(), STSetMatStructure(), STGetMatMode(), STMatMode
|
| 344 |
dsic.upv.es!antodo |
295 |
@*/
|
| 476 |
dsic.upv.es!antodo |
296 |
PetscErrorCode STSetMatMode(ST st,STMatMode mode)
|
| 344 |
dsic.upv.es!antodo |
297 |
{
|
|
|
298 |
PetscFunctionBegin;
|
| 2213 |
jroman |
299 |
PetscValidHeaderSpecific(st,ST_CLASSID,1);
|
| 2326 |
jroman |
300 |
PetscValidLogicalCollectiveEnum(st,mode,2);
|
| 344 |
dsic.upv.es!antodo |
301 |
st->shift_matrix = mode;
|
|
|
302 |
PetscFunctionReturn(0);
|
|
|
303 |
}
|
|
|
304 |
|
| 382 |
dsic.upv.es!antodo |
305 |
#undef __FUNCT__
|
| 444 |
dsic.upv.es!antodo |
306 |
#define __FUNCT__ "STGetMatMode"
|
| 707 |
dsic.upv.es!antodo |
307 |
/*@C
|
| 547 |
dsic.upv.es!jroman |
308 |
STGetMatMode - Gets a flag that indicates how the matrix is being
|
|
|
309 |
shifted in the shift-and-invert and Cayley spectral transformations.
|
|
|
310 |
|
| 2328 |
jroman |
311 |
Not Collective
|
| 547 |
dsic.upv.es!jroman |
312 |
|
|
|
313 |
Input Parameter:
|
|
|
314 |
. st - the spectral transformation context
|
|
|
315 |
|
|
|
316 |
Output Parameter:
|
|
|
317 |
. mode - the mode flag
|
|
|
318 |
|
|
|
319 |
Level: intermediate
|
|
|
320 |
|
| 1364 |
slepc |
321 |
.seealso: STSetMatMode(), STMatMode
|
| 547 |
dsic.upv.es!jroman |
322 |
@*/
|
| 476 |
dsic.upv.es!antodo |
323 |
PetscErrorCode STGetMatMode(ST st,STMatMode *mode)
|
| 444 |
dsic.upv.es!antodo |
324 |
{
|
|
|
325 |
PetscFunctionBegin;
|
| 2213 |
jroman |
326 |
PetscValidHeaderSpecific(st,ST_CLASSID,1);
|
| 2319 |
jroman |
327 |
PetscValidPointer(mode,2);
|
| 444 |
dsic.upv.es!antodo |
328 |
*mode = st->shift_matrix;
|
|
|
329 |
PetscFunctionReturn(0);
|
|
|
330 |
}
|
|
|
331 |
|