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