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