Subversion Repositories slepc-dev

Rev

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
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
#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;
476 dsic.upv.es!antodo 140
  char           type[256];
141
  PetscTruth     flg;
142
  const char     *mode_list[3] = { "copy", "inplace", "shell" };
143
  const char     *structure_list[3] = { "same", "different", "subset" };
144
  PC             pc;
1657 slepc 145
  const char     *pctype;
6 dsic.upv.es!jroman 146
 
147
  PetscFunctionBegin;
25 dsic.upv.es!jroman 148
  PetscValidHeaderSpecific(st,ST_COOKIE,1);
6 dsic.upv.es!jroman 149
 
1422 slepc 150
  ierr = PetscOptionsBegin(((PetscObject)st)->comm,((PetscObject)st)->prefix,"Spectral Transformation (ST) Options","ST");CHKERRQ(ierr);
151
    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 152
    if (flg) {
153
      ierr = STSetType(st,type);CHKERRQ(ierr);
154
    }
155
    /*
156
      Set the type if it was never set.
157
    */
1422 slepc 158
    if (!((PetscObject)st)->type_name) {
106 dsic.upv.es!antodo 159
      ierr = STSetType(st,STSHIFT);CHKERRQ(ierr);
6 dsic.upv.es!jroman 160
    }
161
 
361 dsic.upv.es!antodo 162
    ierr = PetscOptionsScalar("-st_shift","Value of the shift","STSetShift",st->sigma,&st->sigma,PETSC_NULL); 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
 
356 dsic.upv.es!antodo 176
  if (st->ksp) {  
1657 slepc 177
    ierr = KSPGetPC(st->ksp,&pc);CHKERRQ(ierr);
178
    ierr = PCGetType(pc,&pctype);CHKERRQ(ierr);
179
    if (!pctype) {
180
      if (st->shift_matrix == STMATMODE_SHELL) {
181
        /* in shell mode use GMRES with Jacobi as the default */
182
        ierr = KSPSetType(st->ksp,KSPGMRES);CHKERRQ(ierr);
183
        ierr = PCSetType(pc,PCJACOBI);CHKERRQ(ierr);
184
      } else {
185
        /* use direct solver as default */
186
        ierr = KSPSetType(st->ksp,KSPPREONLY);CHKERRQ(ierr);
1667 slepc 187
        ierr = PCSetType(pc,PCREDUNDANT);CHKERRQ(ierr);
1657 slepc 188
      }
356 dsic.upv.es!antodo 189
    }
190
    ierr = KSPSetFromOptions(st->ksp);CHKERRQ(ierr);
191
  }
192
 
6 dsic.upv.es!jroman 193
  PetscFunctionReturn(0);
194
}
195
 
344 dsic.upv.es!antodo 196
#undef __FUNCT__  
197
#define __FUNCT__ "STSetMatStructure"
198
/*@
199
   STSetMatStructure - Sets an internal MatStructure attribute to
200
   indicate which is the relation of the sparsity pattern of the two matrices
201
   A and B constituting the generalized eigenvalue problem. This function
202
   has no effect in the case of standard eigenproblems.
203
 
204
   Collective on ST
205
 
206
   Input Parameters:
207
+  st  - the spectral transformation context
208
-  str - either SAME_NONZERO_PATTERN, DIFFERENT_NONZERO_PATTERN or
209
         SUBSET_NONZERO_PATTERN
210
 
211
   Options Database Key:
354 dsic.upv.es!jroman 212
.  -st_matstructure <str> - Indicates the structure flag, where <str> is one
213
         of 'same' (A and B have the same nonzero pattern), 'different' (A
214
         and B have different nonzero pattern) or 'subset' (B's nonzero
215
         pattern is a subset of A's).
344 dsic.upv.es!antodo 216
 
217
   Note:
218
   By default, the sparsity patterns are assumed to be different. If the
219
   patterns are equal or a subset then it is recommended to set this attribute
220
   for efficiency reasons (in particular, for internal MatAXPY() operations).
221
 
222
   Level: advanced
223
 
224
.seealso: STSetOperators(), MatAXPY()
225
@*/
476 dsic.upv.es!antodo 226
PetscErrorCode STSetMatStructure(ST st,MatStructure str)
344 dsic.upv.es!antodo 227
{
228
  PetscFunctionBegin;
229
  PetscValidHeaderSpecific(st,ST_COOKIE,1);
1241 slepc 230
  switch (str) {
231
    case SAME_NONZERO_PATTERN:
232
    case DIFFERENT_NONZERO_PATTERN:
233
    case SUBSET_NONZERO_PATTERN:
234
      st->str = str;
235
      break;
236
    default:
237
      SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,"Invalid matrix structure flag");
238
  }
344 dsic.upv.es!antodo 239
  PetscFunctionReturn(0);
240
}
241
 
242
#undef __FUNCT__  
243
#define __FUNCT__ "STSetMatMode"
244
/*@
245
   STSetMatMode - Sets a flag to indicate how the matrix is
246
   being shifted in the shift-and-invert and Cayley spectral transformations.
247
 
248
   Collective on ST
249
 
250
   Input Parameters:
251
+  st - the spectral transformation context
252
-  mode - the mode flag, one of STMATMODE_COPY,
253
          STMATMODE_INPLACE or STMATMODE_SHELL
254
 
255
   Options Database Key:
354 dsic.upv.es!jroman 256
.  -st_matmode <mode> - Indicates the mode flag, where <mode> is one of
257
          'copy', 'inplace' or 'shell' (see explanation below).
344 dsic.upv.es!antodo 258
 
354 dsic.upv.es!jroman 259
   Notes:
344 dsic.upv.es!antodo 260
   By default (STMATMODE_COPY), a copy of matrix A is made and then
261
   this copy is shifted explicitly, e.g. A <- (A - s B).
262
 
263
   With STMATMODE_INPLACE, the original matrix A is shifted at
264
   STSetUp() and unshifted at the end of the computations. With respect to
265
   the previous one, this mode avoids a copy of matrix A. However, a
266
   backdraw is that the recovered matrix might be slightly different
267
   from the original one (due to roundoff).
268
 
269
   With STMATMODE_SHELL, the solver works with an implicit shell
270
   matrix that represents the shifted matrix. This mode is the most efficient
271
   in creating the shifted matrix but it places serious limitations to the
272
   linear solves performed in each iteration of the eigensolver (typically,
273
   only interative solvers with Jacobi preconditioning can be used).
274
 
275
   In the case of generalized problems, in the two first modes the matrix
276
   A - s B has to be computed explicitly. The efficiency of this computation
354 dsic.upv.es!jroman 277
   can be controlled with STSetMatStructure().
344 dsic.upv.es!antodo 278
 
279
   Level: intermediate
280
 
1364 slepc 281
.seealso: STSetOperators(), STSetMatStructure(), STGetMatMode(), STMatMode
344 dsic.upv.es!antodo 282
@*/
476 dsic.upv.es!antodo 283
PetscErrorCode STSetMatMode(ST st,STMatMode mode)
344 dsic.upv.es!antodo 284
{
285
  PetscFunctionBegin;
356 dsic.upv.es!antodo 286
  PetscValidHeaderSpecific(st,ST_COOKIE,1);
344 dsic.upv.es!antodo 287
  st->shift_matrix = mode;
288
  PetscFunctionReturn(0);
289
}
290
 
382 dsic.upv.es!antodo 291
#undef __FUNCT__  
444 dsic.upv.es!antodo 292
#define __FUNCT__ "STGetMatMode"
707 dsic.upv.es!antodo 293
/*@C
547 dsic.upv.es!jroman 294
   STGetMatMode - Gets a flag that indicates how the matrix is being
295
   shifted in the shift-and-invert and Cayley spectral transformations.
296
 
297
   Collective on ST
298
 
299
   Input Parameter:
300
.  st - the spectral transformation context
301
 
302
   Output Parameter:
303
.  mode - the mode flag
304
 
305
   Level: intermediate
306
 
1364 slepc 307
.seealso: STSetMatMode(), STMatMode
547 dsic.upv.es!jroman 308
@*/
476 dsic.upv.es!antodo 309
PetscErrorCode STGetMatMode(ST st,STMatMode *mode)
444 dsic.upv.es!antodo 310
{
311
  PetscFunctionBegin;
312
  PetscValidHeaderSpecific(st,ST_COOKIE,1);
313
  *mode = st->shift_matrix;
314
  PetscFunctionReturn(0);
315
}
316