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
1976 eromero 1
/*
2110 jroman 2
  SLEPc eigensolver: "gd"
1976 eromero 3
 
2110 jroman 4
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
5
   SLEPc - Scalable Library for Eigenvalue Problem Computations
2116 eromero 6
   Copyright (c) 2002-2010, Universidad Politecnica de Valencia, Spain
1976 eromero 7
 
2110 jroman 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/>.
21
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1976 eromero 22
*/
23
 
24
#include "private/epsimpl.h"                /*I "slepceps.h" I*/
25
#include "private/stimpl.h"
1985 eromero 26
#include "../src/eps/impls/davidson/common/davidson.h"
1976 eromero 27
#include "slepcblaslapack.h"
28
 
2003 eromero 29
PetscErrorCode EPSSetUp_GD(EPS eps);
1992 eromero 30
PetscErrorCode EPSDestroy_GD(EPS eps);
1976 eromero 31
 
32
EXTERN_C_BEGIN
33
#undef __FUNCT__  
34
#define __FUNCT__ "EPSSetFromOptions_GD"
35
PetscErrorCode EPSSetFromOptions_GD(EPS eps)
36
{
37
  PetscErrorCode  ierr;
38
  PetscTruth      flg,op;
39
  PetscInt        opi,opi0;
40
 
41
  PetscFunctionBegin;
42
 
2102 eromero 43
  ierr = PetscOptionsBegin(((PetscObject)eps)->comm,((PetscObject)eps)->prefix,"GD Options","EPS");CHKERRQ(ierr);
1976 eromero 44
 
45
  ierr = EPSGDGetKrylovStart(eps, &op); CHKERRQ(ierr);
46
  ierr = PetscOptionsTruth("-eps_gd_krylov_start","Start the searching subspace with a krylov basis","EPSGDSetKrylovStart",op,&op,&flg); CHKERRQ(ierr);
47
  if(flg) { ierr = EPSGDSetKrylovStart(eps, op); CHKERRQ(ierr); }
48
 
49
  ierr = EPSGDGetBlockSize(eps, &opi); CHKERRQ(ierr);
50
  ierr = PetscOptionsInt("-eps_gd_blocksize","Number vectors add to the searching subspace (if 0, nev employed)","EPSGDSetBlockSize",opi,&opi,&flg); CHKERRQ(ierr);
51
  if(flg) { ierr = EPSGDSetBlockSize(eps, opi); CHKERRQ(ierr); }
52
 
53
  ierr = EPSGDGetRestart(eps, &opi, &opi0); CHKERRQ(ierr);
54
  ierr = PetscOptionsInt("-eps_gd_minv","Set the size of the searching subspace after restarting (if 0, eps_gd_bs is employed)","EPSGDSetRestart",opi,&opi,&flg); CHKERRQ(ierr);
55
  if(flg) { ierr = EPSGDSetRestart(eps, opi, opi0); CHKERRQ(ierr); }
56
 
57
  ierr = PetscOptionsInt("-eps_gd_plusk","Set the number of saved eigenvectors from the previous iteration when restarting","EPSGDSetRestart",opi0,&opi0,&flg); CHKERRQ(ierr);
58
  if(flg) { ierr = EPSGDSetRestart(eps, opi, opi0); CHKERRQ(ierr); }
59
 
1980 eromero 60
  ierr = EPSGDGetInitialSize(eps, &opi); CHKERRQ(ierr);
61
  ierr = PetscOptionsInt("-eps_gd_initial_size","Set the initial size of the searching subspace","EPSGDSetInitialSize",opi,&opi,&flg); CHKERRQ(ierr);
62
  if(flg) { ierr = EPSGDSetInitialSize(eps, opi); CHKERRQ(ierr); }
63
 
2102 eromero 64
  ierr = PetscOptionsEnd();CHKERRQ(ierr);
1976 eromero 65
 
66
  PetscFunctionReturn(0);
67
}  
68
EXTERN_C_END
69
 
70
 
71
#undef __FUNCT__  
2003 eromero 72
#define __FUNCT__ "EPSSetUp_GD"
73
PetscErrorCode EPSSetUp_GD(EPS eps)
74
{
75
  PetscErrorCode  ierr;
76
  PetscTruth      t;
77
  KSP             ksp;
78
 
79
  PetscFunctionBegin;
80
 
2104 eromero 81
  /* Setup common for all davidson solvers */
82
  ierr = EPSSetUp_DAVIDSON(eps); CHKERRQ(ierr);
83
 
2003 eromero 84
  /* Check some constraints */
85
  ierr = STSetUp(eps->OP); CHKERRQ(ierr);
86
  ierr = STGetKSP(eps->OP, &ksp); CHKERRQ(ierr);
87
  ierr = PetscTypeCompare((PetscObject)ksp, KSPPREONLY, &t); CHKERRQ(ierr);
2214 jroman 88
  if (!t) SETERRQ(((PetscObject)eps)->comm,PETSC_ERR_SUP, "EPSGD only works with KSPPREONLY");
2003 eromero 89
 
90
  PetscFunctionReturn(0);
91
}
92
 
93
 
94
EXTERN_C_BEGIN
95
#undef __FUNCT__  
1976 eromero 96
#define __FUNCT__ "EPSCreate_GD"
97
PetscErrorCode EPSCreate_GD(EPS eps) {
98
  PetscErrorCode  ierr;
99
 
100
  PetscFunctionBegin;
101
 
1982 eromero 102
  /* Load the DAVIDSON solver */
103
  ierr = EPSCreate_DAVIDSON(eps); CHKERRQ(ierr);
1976 eromero 104
 
1982 eromero 105
  /* Overload the GD properties */
1976 eromero 106
  eps->ops->setfromoptions       = EPSSetFromOptions_GD;
2003 eromero 107
  eps->ops->setup                = EPSSetUp_GD;
1992 eromero 108
  eps->ops->destroy              = EPSDestroy_GD;
1976 eromero 109
 
1982 eromero 110
  ierr = PetscObjectComposeFunctionDynamic((PetscObject)eps,"EPSGDSetKrylovStart_C","EPSDAVIDSONSetKrylovStart_DAVIDSON",EPSDAVIDSONSetKrylovStart_DAVIDSON);CHKERRQ(ierr);
111
  ierr = PetscObjectComposeFunctionDynamic((PetscObject)eps,"EPSGDGetKrylovStart_C","EPSDAVIDSONGetKrylovStart_DAVIDSON",EPSDAVIDSONGetKrylovStart_DAVIDSON);CHKERRQ(ierr);
112
  ierr = PetscObjectComposeFunctionDynamic((PetscObject)eps,"EPSGDSetBlockSize_C","EPSDAVIDSONSetBlockSize_DAVIDSON",EPSDAVIDSONSetBlockSize_DAVIDSON);CHKERRQ(ierr);
113
  ierr = PetscObjectComposeFunctionDynamic((PetscObject)eps,"EPSGDGetBlockSize_C","EPSDAVIDSONGetBlockSize_DAVIDSON",EPSDAVIDSONGetBlockSize_DAVIDSON);CHKERRQ(ierr);
114
  ierr = PetscObjectComposeFunctionDynamic((PetscObject)eps,"EPSGDSetRestart_C","EPSDAVIDSONSetRestart_DAVIDSON",EPSDAVIDSONSetRestart_DAVIDSON);CHKERRQ(ierr);
115
  ierr = PetscObjectComposeFunctionDynamic((PetscObject)eps,"EPSGDGetRestart_C","EPSDAVIDSONGetRestart_DAVIDSON",EPSDAVIDSONGetRestart_DAVIDSON);CHKERRQ(ierr);
116
  ierr = PetscObjectComposeFunctionDynamic((PetscObject)eps,"EPSGDSetInitialSize_C","EPSDAVIDSONSetInitialSize_DAVIDSON",EPSDAVIDSONSetInitialSize_DAVIDSON);CHKERRQ(ierr);
117
  ierr = PetscObjectComposeFunctionDynamic((PetscObject)eps,"EPSGDGetInitialSize_C","EPSDAVIDSONGetInitialSize_DAVIDSON",EPSDAVIDSONGetInitialSize_DAVIDSON);CHKERRQ(ierr);
1976 eromero 118
 
119
  PetscFunctionReturn(0);
120
}
121
EXTERN_C_END
122
 
1980 eromero 123
#undef __FUNCT__  
1992 eromero 124
#define __FUNCT__ "EPSDestroy_GD"
125
PetscErrorCode EPSDestroy_GD(EPS eps)
126
{
1980 eromero 127
  PetscErrorCode  ierr;
1976 eromero 128
 
1980 eromero 129
  PetscFunctionBegin;
130
 
131
  ierr = PetscObjectComposeFunctionDynamic((PetscObject)eps,"EPSGDSetKrylovStart_C","",PETSC_NULL);CHKERRQ(ierr);
132
  ierr = PetscObjectComposeFunctionDynamic((PetscObject)eps,"EPSGDGetKrylovStart_C","",PETSC_NULL);CHKERRQ(ierr);
133
  ierr = PetscObjectComposeFunctionDynamic((PetscObject)eps,"EPSGDSetBlockSize_C","",PETSC_NULL);CHKERRQ(ierr);
134
  ierr = PetscObjectComposeFunctionDynamic((PetscObject)eps,"EPSGDGetBlockSize_C","",PETSC_NULL);CHKERRQ(ierr);
135
  ierr = PetscObjectComposeFunctionDynamic((PetscObject)eps,"EPSGDSetRestart_C","",PETSC_NULL);CHKERRQ(ierr);
136
  ierr = PetscObjectComposeFunctionDynamic((PetscObject)eps,"EPSGDGetRestart_C","",PETSC_NULL);CHKERRQ(ierr);
137
  ierr = PetscObjectComposeFunctionDynamic((PetscObject)eps,"EPSGDSetInitialSize_C","",PETSC_NULL);CHKERRQ(ierr);
138
  ierr = PetscObjectComposeFunctionDynamic((PetscObject)eps,"EPSGDGetInitialSize_C","",PETSC_NULL);CHKERRQ(ierr);
139
 
1992 eromero 140
  ierr = EPSDestroy_DAVIDSON(eps);
141
 
1980 eromero 142
  PetscFunctionReturn(0);
143
}
144
 
145
 
1976 eromero 146
#undef __FUNCT__  
147
#define __FUNCT__ "EPSGDSetKrylovStart"
148
/*@
149
   EPSGDSetKrylovStart - Activates or deactivates starting the searching
150
   subspace with a Krylov basis.
151
 
152
   Collective on EPS
153
 
154
   Input Parameters:
155
+  eps - the eigenproblem solver context
156
-  krylovstart - boolean flag
157
 
158
   Options Database Key:
159
.  -eps_gd_krylovstart - Activates starting the searching subspace with a
160
    Krylov basis
161
 
162
   Level: advanced
163
 
164
.seealso: EPSGDGetKrylovStart()
165
@*/
1980 eromero 166
PetscErrorCode EPSGDSetKrylovStart(EPS eps,PetscTruth krylovstart)
167
{
168
  PetscErrorCode ierr, (*f)(EPS,PetscTruth);
1976 eromero 169
 
1980 eromero 170
  PetscFunctionBegin;
2213 jroman 171
  PetscValidHeaderSpecific(eps,EPS_CLASSID,1);
1980 eromero 172
  ierr = PetscObjectQueryFunction((PetscObject)eps,"EPSGDSetKrylovStart_C",(void (**)())&f);CHKERRQ(ierr);
173
  if (f) {
174
    ierr = (*f)(eps,krylovstart);CHKERRQ(ierr);
175
  }
176
  PetscFunctionReturn(0);
177
}
1976 eromero 178
 
179
#undef __FUNCT__  
180
#define __FUNCT__ "EPSGDGetKrylovStart"
1985 eromero 181
/*@
1976 eromero 182
   EPSGDGetKrylovStart - Gets if the searching subspace is started with a
183
   Krylov basis.
184
 
185
   Collective on EPS
186
 
187
   Input Parameter:
188
.  eps - the eigenproblem solver context
189
 
1994 eromero 190
   Output Parameters:
1976 eromero 191
.  krylovstart - boolean flag indicating if starting the searching subspace
192
   with a Krylov basis is enabled.
193
 
194
   Level: advanced
195
 
196
.seealso: EPSGDGetKrylovStart()
197
@*/
1980 eromero 198
PetscErrorCode EPSGDGetKrylovStart(EPS eps,PetscTruth *krylovstart)
199
{
200
  PetscErrorCode ierr, (*f)(EPS,PetscTruth*);
1976 eromero 201
 
1980 eromero 202
  PetscFunctionBegin;
2213 jroman 203
  PetscValidHeaderSpecific(eps,EPS_CLASSID,1);
1984 eromero 204
  ierr = PetscObjectQueryFunction((PetscObject)eps,"EPSGDGetKrylovStart_C",(void (**)())&f);CHKERRQ(ierr);
1980 eromero 205
  if (f) {
206
    ierr = (*f)(eps,krylovstart);CHKERRQ(ierr);
207
  }
208
  PetscFunctionReturn(0);
209
}
210
 
1976 eromero 211
#undef __FUNCT__  
212
#define __FUNCT__ "EPSGDSetBlockSize"
213
/*@
214
   EPSGDSetBlockSize - Sets the number of vectors added to the searching space
215
   every iteration.
216
 
217
   Collective on EPS
218
 
219
   Input Parameters:
220
+  eps - the eigenproblem solver context
221
-  blocksize - non-zero positive integer
222
 
223
   Options Database Key:
224
.  -eps_gd_blocksize - integer indicating the number of vectors added to the
225
   searching space every iteration.
226
 
227
   Level: advanced
228
 
229
.seealso: EPSGDSetKrylovStart()
230
@*/
1980 eromero 231
PetscErrorCode EPSGDSetBlockSize(EPS eps,PetscInt blocksize)
232
{
233
  PetscErrorCode ierr, (*f)(EPS,PetscInt);
1976 eromero 234
 
1980 eromero 235
  PetscFunctionBegin;
2213 jroman 236
  PetscValidHeaderSpecific(eps,EPS_CLASSID,1);
1980 eromero 237
  ierr = PetscObjectQueryFunction((PetscObject)eps,"EPSGDSetBlockSize_C",(void (**)())&f);CHKERRQ(ierr);
238
  if (f) {
239
    ierr = (*f)(eps,blocksize);CHKERRQ(ierr);
240
  }
241
  PetscFunctionReturn(0);
242
}
243
 
1976 eromero 244
#undef __FUNCT__  
245
#define __FUNCT__ "EPSGDGetBlockSize"
1985 eromero 246
/*@
1976 eromero 247
   EPSGDGetBlockSize - Gets the number of vectors added to the searching space
248
   every iteration.
249
 
250
   Collective on EPS
251
 
252
   Input Parameter:
253
.  eps - the eigenproblem solver context
254
 
1994 eromero 255
   Output Parameter:
1976 eromero 256
.  blocksize - integer indicating the number of vectors added to the searching
257
   space every iteration.
258
 
259
   Level: advanced
260
 
261
.seealso: EPSGDSetBlockSize()
262
@*/
1980 eromero 263
PetscErrorCode EPSGDGetBlockSize(EPS eps,PetscInt *blocksize)
264
{
265
  PetscErrorCode ierr, (*f)(EPS,PetscInt*);
1976 eromero 266
 
1980 eromero 267
  PetscFunctionBegin;
2213 jroman 268
  PetscValidHeaderSpecific(eps,EPS_CLASSID,1);
1980 eromero 269
  ierr = PetscObjectQueryFunction((PetscObject)eps,"EPSGDGetBlockSize_C",(void (**)())&f);CHKERRQ(ierr);
270
  if (f) {
271
    ierr = (*f)(eps,blocksize);CHKERRQ(ierr);
272
  }
273
  PetscFunctionReturn(0);
274
}
275
 
1976 eromero 276
#undef __FUNCT__  
277
#define __FUNCT__ "EPSGDGetRestart"
1985 eromero 278
/*@
1976 eromero 279
   EPSGDGetRestart - Gets the number of vectors of the searching space after
280
   restarting and the number of vectors saved from the previous iteration.
281
 
282
   Collective on EPS
283
 
284
   Input Parameter:
285
.  eps - the eigenproblem solver context
286
 
1994 eromero 287
   Output Parameter:
1976 eromero 288
+  minv - non-zero positive integer indicating the number of vectors of the
289
   searching subspace after restarting
290
-  plusk - positive integer indicating the number of vectors saved from the
291
   previous iteration  
292
 
293
   Level: advanced
294
 
295
.seealso: EPSGDSetRestart()
296
@*/
1980 eromero 297
PetscErrorCode EPSGDGetRestart(EPS eps,PetscInt *minv,PetscInt *plusk)
298
{
299
  PetscErrorCode ierr, (*f)(EPS,PetscInt*,PetscInt*);
1976 eromero 300
 
1980 eromero 301
  PetscFunctionBegin;
2213 jroman 302
  PetscValidHeaderSpecific(eps,EPS_CLASSID,1);
1980 eromero 303
  ierr = PetscObjectQueryFunction((PetscObject)eps,"EPSGDGetRestart_C",(void (**)())&f);CHKERRQ(ierr);
304
  if (f) {
305
    ierr = (*f)(eps,minv,plusk);CHKERRQ(ierr);
306
  }
307
  PetscFunctionReturn(0);
308
}
309
 
1976 eromero 310
#undef __FUNCT__  
311
#define __FUNCT__ "EPSGDSetRestart"
312
/*@
313
   EPSGDSetRestart - Sets the number of vectors of the searching space after
314
   restarting and the number of vectors saved from the previous iteration.
315
 
316
   Collective on EPS
317
 
318
   Input Parameters:
319
+  eps - the eigenproblem solver context
320
.  minv - non-zero positive integer indicating the number of vectors of the
321
   searching subspace after restarting
322
-  plusk - positive integer indicating the number of vectors saved from the
323
   previous iteration  
324
 
325
   Options Database Key:
326
+  -eps_gd_minv - non-zero positive integer indicating the number of vectors
327
    of the searching subspace after restarting
328
-  -eps_gd_plusk - positive integer indicating the number of vectors saved
329
    from the previous iteration  
330
 
331
   Level: advanced
332
 
333
.seealso: EPSGDSetRestart()
334
@*/
1980 eromero 335
PetscErrorCode EPSGDSetRestart(EPS eps,PetscInt minv,PetscInt plusk)
336
{
337
  PetscErrorCode ierr, (*f)(EPS,PetscInt,PetscInt);
1976 eromero 338
 
1980 eromero 339
  PetscFunctionBegin;
2213 jroman 340
  PetscValidHeaderSpecific(eps,EPS_CLASSID,1);
1980 eromero 341
  ierr = PetscObjectQueryFunction((PetscObject)eps,"EPSGDSetRestart_C",(void (**)())&f);CHKERRQ(ierr);
342
  if (f) {
343
    ierr = (*f)(eps,minv,plusk);CHKERRQ(ierr);
344
  }
345
  PetscFunctionReturn(0);
346
}
1976 eromero 347
 
1980 eromero 348
#undef __FUNCT__  
349
#define __FUNCT__ "EPSGDGetInitialSize"
1985 eromero 350
/*@
1980 eromero 351
   EPSGDGetInitialSize - Gets the initial size of the searching space. In the
352
   case of EPSGetKrylovStart is PETSC_FALSE and the user provides vectors by
353
   EPSSetInitialSpace, up to initialsize vectors will be used; and if the
354
   provided vectors are not enough, the solver completes the subspace with
355
   random vectors. In the case of EPSGetKrylovStart is PETSC_TRUE, the solver
356
   gets the first vector provided by the user or, if not, a random vector,
357
   and expands the Krylov basis up to initialsize vectors.
358
 
359
   Collective on EPS
360
 
361
   Input Parameter:
362
.  eps - the eigenproblem solver context
363
 
1994 eromero 364
   Output Parameter:
1980 eromero 365
.  initialsize - non-zero positive integer indicating the number of vectors of
366
   the initial searching subspace
367
 
368
   Level: advanced
369
 
370
.seealso: EPSGDSetInitialSize(), EPSGetKrylovStart()
371
@*/
372
PetscErrorCode EPSGDGetInitialSize(EPS eps,PetscInt *initialsize)
373
{
374
  PetscErrorCode ierr, (*f)(EPS,PetscInt*);
375
 
376
  PetscFunctionBegin;
2213 jroman 377
  PetscValidHeaderSpecific(eps,EPS_CLASSID,1);
1980 eromero 378
  ierr = PetscObjectQueryFunction((PetscObject)eps,"EPSGDGetInitialSize_C",(void (**)())&f);CHKERRQ(ierr);
379
  if (f) {
380
    ierr = (*f)(eps,initialsize);CHKERRQ(ierr);
381
  }
382
  PetscFunctionReturn(0);
383
}
384
 
385
#undef __FUNCT__  
386
#define __FUNCT__ "EPSGDSetInitialSize"
387
/*@
388
   EPSGDSetInitialSize - Sets the initial size of the searching space. In the
389
   case of EPSGetKrylovStart is PETSC_FALSE and the user provides vectors by
390
   EPSSetInitialSpace, up to initialsize vectors will be used; and if the
391
   provided vectors are not enough, the solver completes the subspace with
392
   random vectors. In the case of EPSGetKrylovStart is PETSC_TRUE, the solver
393
   gets the first vector provided by the user or, if not, a random vector,
394
   and expands the Krylov basis up to initialsize vectors.
395
 
396
   Collective on EPS
397
 
1994 eromero 398
   Input Parameters:
399
+  eps - the eigenproblem solver context
400
-  initialsize - non-zero positive integer indicating the number of vectors of
1980 eromero 401
   the initial searching subspace
402
 
403
   Options Database Key:
404
.  -eps_gd_initial_size - non-zero positive integer indicating the number of
405
    vectors of the initial searching subspace
406
 
407
   Level: advanced
408
 
1994 eromero 409
.seealso: EPSGDGetInitialSize(), EPSGetKrylovStart()
1980 eromero 410
@*/
411
PetscErrorCode EPSGDSetInitialSize(EPS eps,PetscInt initialsize)
412
{
413
  PetscErrorCode ierr, (*f)(EPS,PetscInt);
414
 
415
  PetscFunctionBegin;
2213 jroman 416
  PetscValidHeaderSpecific(eps,EPS_CLASSID,1);
1980 eromero 417
  ierr = PetscObjectQueryFunction((PetscObject)eps,"EPSGDSetInitialSize_C",(void (**)())&f);CHKERRQ(ierr);
418
  if (f) {
419
    ierr = (*f)(eps,initialsize);CHKERRQ(ierr);
420
  }
421
  PetscFunctionReturn(0);
422
}
423