Subversion Repositories slepc-dev

Rev

Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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