Subversion Repositories slepc-dev

Rev

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;
2216 jroman 38
  PetscBool       flg,op;
1976 eromero 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);
2216 jroman 46
  ierr = PetscOptionsBool("-eps_gd_krylov_start","Start the searching subspace with a krylov basis","EPSGDSetKrylovStart",op,&op,&flg); CHKERRQ(ierr);
1976 eromero 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;
2216 jroman 76
  PetscBool       t;
2003 eromero 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
@*/
2216 jroman 166
PetscErrorCode EPSGDSetKrylovStart(EPS eps,PetscBool krylovstart)
1980 eromero 167
{
2221 jroman 168
  PetscErrorCode ierr;
1976 eromero 169
 
1980 eromero 170
  PetscFunctionBegin;
2213 jroman 171
  PetscValidHeaderSpecific(eps,EPS_CLASSID,1);
2221 jroman 172
  ierr = PetscTryMethod(eps,"EPSGDSetKrylovStart_C",(EPS,PetscBool),(eps,krylovstart));CHKERRQ(ierr);
1980 eromero 173
  PetscFunctionReturn(0);
174
}
1976 eromero 175
 
176
#undef __FUNCT__  
177
#define __FUNCT__ "EPSGDGetKrylovStart"
1985 eromero 178
/*@
1976 eromero 179
   EPSGDGetKrylovStart - Gets if the searching subspace is started with a
180
   Krylov basis.
181
 
182
   Collective on EPS
183
 
184
   Input Parameter:
185
.  eps - the eigenproblem solver context
186
 
1994 eromero 187
   Output Parameters:
1976 eromero 188
.  krylovstart - boolean flag indicating if starting the searching subspace
189
   with a Krylov basis is enabled.
190
 
191
   Level: advanced
192
 
193
.seealso: EPSGDGetKrylovStart()
194
@*/
2216 jroman 195
PetscErrorCode EPSGDGetKrylovStart(EPS eps,PetscBool *krylovstart)
1980 eromero 196
{
2221 jroman 197
  PetscErrorCode ierr;
1976 eromero 198
 
1980 eromero 199
  PetscFunctionBegin;
2213 jroman 200
  PetscValidHeaderSpecific(eps,EPS_CLASSID,1);
2221 jroman 201
  ierr = PetscTryMethod(eps,"EPSGDGetKrylovStart_C",(EPS,PetscBool*),(eps,krylovstart));CHKERRQ(ierr);
1980 eromero 202
  PetscFunctionReturn(0);
203
}
204
 
1976 eromero 205
#undef __FUNCT__  
206
#define __FUNCT__ "EPSGDSetBlockSize"
207
/*@
208
   EPSGDSetBlockSize - Sets the number of vectors added to the searching space
209
   every iteration.
210
 
211
   Collective on EPS
212
 
213
   Input Parameters:
214
+  eps - the eigenproblem solver context
215
-  blocksize - non-zero positive integer
216
 
217
   Options Database Key:
218
.  -eps_gd_blocksize - integer indicating the number of vectors added to the
219
   searching space every iteration.
220
 
221
   Level: advanced
222
 
223
.seealso: EPSGDSetKrylovStart()
224
@*/
1980 eromero 225
PetscErrorCode EPSGDSetBlockSize(EPS eps,PetscInt blocksize)
226
{
2221 jroman 227
  PetscErrorCode ierr;
1976 eromero 228
 
1980 eromero 229
  PetscFunctionBegin;
2213 jroman 230
  PetscValidHeaderSpecific(eps,EPS_CLASSID,1);
2221 jroman 231
  ierr = PetscTryMethod(eps,"EPSGDSetBlockSize_C",(EPS,PetscInt),(eps,blocksize));CHKERRQ(ierr);
1980 eromero 232
  PetscFunctionReturn(0);
233
}
234
 
1976 eromero 235
#undef __FUNCT__  
236
#define __FUNCT__ "EPSGDGetBlockSize"
1985 eromero 237
/*@
1976 eromero 238
   EPSGDGetBlockSize - Gets the number of vectors added to the searching space
239
   every iteration.
240
 
241
   Collective on EPS
242
 
243
   Input Parameter:
244
.  eps - the eigenproblem solver context
245
 
1994 eromero 246
   Output Parameter:
1976 eromero 247
.  blocksize - integer indicating the number of vectors added to the searching
248
   space every iteration.
249
 
250
   Level: advanced
251
 
252
.seealso: EPSGDSetBlockSize()
253
@*/
1980 eromero 254
PetscErrorCode EPSGDGetBlockSize(EPS eps,PetscInt *blocksize)
255
{
2221 jroman 256
  PetscErrorCode ierr;
1976 eromero 257
 
1980 eromero 258
  PetscFunctionBegin;
2213 jroman 259
  PetscValidHeaderSpecific(eps,EPS_CLASSID,1);
2221 jroman 260
  ierr = PetscTryMethod(eps,"EPSGDGetBlockSize_C",(EPS,PetscInt*),(eps,blocksize));CHKERRQ(ierr);
1980 eromero 261
  PetscFunctionReturn(0);
262
}
263
 
1976 eromero 264
#undef __FUNCT__  
265
#define __FUNCT__ "EPSGDGetRestart"
1985 eromero 266
/*@
1976 eromero 267
   EPSGDGetRestart - Gets the number of vectors of the searching space after
268
   restarting and the number of vectors saved from the previous iteration.
269
 
270
   Collective on EPS
271
 
272
   Input Parameter:
273
.  eps - the eigenproblem solver context
274
 
1994 eromero 275
   Output Parameter:
1976 eromero 276
+  minv - non-zero positive integer indicating the number of vectors of the
277
   searching subspace after restarting
278
-  plusk - positive integer indicating the number of vectors saved from the
279
   previous iteration  
280
 
281
   Level: advanced
282
 
283
.seealso: EPSGDSetRestart()
284
@*/
1980 eromero 285
PetscErrorCode EPSGDGetRestart(EPS eps,PetscInt *minv,PetscInt *plusk)
286
{
2221 jroman 287
  PetscErrorCode ierr;
1976 eromero 288
 
1980 eromero 289
  PetscFunctionBegin;
2213 jroman 290
  PetscValidHeaderSpecific(eps,EPS_CLASSID,1);
2221 jroman 291
  ierr = PetscTryMethod(eps,"EPSGDGetRestart_C",(EPS,PetscInt*,PetscInt*),(eps,minv,plusk));CHKERRQ(ierr);
1980 eromero 292
  PetscFunctionReturn(0);
293
}
294
 
1976 eromero 295
#undef __FUNCT__  
296
#define __FUNCT__ "EPSGDSetRestart"
297
/*@
298
   EPSGDSetRestart - Sets the number of vectors of the searching space after
299
   restarting and the number of vectors saved from the previous iteration.
300
 
301
   Collective on EPS
302
 
303
   Input Parameters:
304
+  eps - the eigenproblem solver context
305
.  minv - non-zero positive integer indicating the number of vectors of the
306
   searching subspace after restarting
307
-  plusk - positive integer indicating the number of vectors saved from the
308
   previous iteration  
309
 
310
   Options Database Key:
311
+  -eps_gd_minv - non-zero positive integer indicating the number of vectors
312
    of the searching subspace after restarting
313
-  -eps_gd_plusk - positive integer indicating the number of vectors saved
314
    from the previous iteration  
315
 
316
   Level: advanced
317
 
318
.seealso: EPSGDSetRestart()
319
@*/
1980 eromero 320
PetscErrorCode EPSGDSetRestart(EPS eps,PetscInt minv,PetscInt plusk)
321
{
2221 jroman 322
  PetscErrorCode ierr;
1976 eromero 323
 
1980 eromero 324
  PetscFunctionBegin;
2213 jroman 325
  PetscValidHeaderSpecific(eps,EPS_CLASSID,1);
2221 jroman 326
  ierr = PetscTryMethod(eps,"EPSGDSetRestart_C",(EPS,PetscInt,PetscInt),(eps,minv,plusk));CHKERRQ(ierr);
1980 eromero 327
  PetscFunctionReturn(0);
328
}
1976 eromero 329
 
1980 eromero 330
#undef __FUNCT__  
331
#define __FUNCT__ "EPSGDGetInitialSize"
1985 eromero 332
/*@
1980 eromero 333
   EPSGDGetInitialSize - Gets the initial size of the searching space. In the
2242 jroman 334
   case of EPSGDGetKrylovStart is PETSC_FALSE and the user provides vectors by
1980 eromero 335
   EPSSetInitialSpace, up to initialsize vectors will be used; and if the
336
   provided vectors are not enough, the solver completes the subspace with
2242 jroman 337
   random vectors. In the case of EPSGDGetKrylovStart is PETSC_TRUE, the solver
1980 eromero 338
   gets the first vector provided by the user or, if not, a random vector,
339
   and expands the Krylov basis up to initialsize vectors.
340
 
341
   Collective on EPS
342
 
343
   Input Parameter:
344
.  eps - the eigenproblem solver context
345
 
1994 eromero 346
   Output Parameter:
1980 eromero 347
.  initialsize - non-zero positive integer indicating the number of vectors of
348
   the initial searching subspace
349
 
350
   Level: advanced
351
 
2242 jroman 352
.seealso: EPSGDSetInitialSize(), EPSGDGetKrylovStart()
1980 eromero 353
@*/
354
PetscErrorCode EPSGDGetInitialSize(EPS eps,PetscInt *initialsize)
355
{
2221 jroman 356
  PetscErrorCode ierr;
1980 eromero 357
 
358
  PetscFunctionBegin;
2213 jroman 359
  PetscValidHeaderSpecific(eps,EPS_CLASSID,1);
2221 jroman 360
  ierr = PetscTryMethod(eps,"EPSGDGetInitialSize_C",(EPS,PetscInt*),(eps,initialsize));CHKERRQ(ierr);
1980 eromero 361
  PetscFunctionReturn(0);
362
}
363
 
364
#undef __FUNCT__  
365
#define __FUNCT__ "EPSGDSetInitialSize"
366
/*@
367
   EPSGDSetInitialSize - Sets the initial size of the searching space. In the
2242 jroman 368
   case of EPSGDGetKrylovStart is PETSC_FALSE and the user provides vectors by
1980 eromero 369
   EPSSetInitialSpace, up to initialsize vectors will be used; and if the
370
   provided vectors are not enough, the solver completes the subspace with
2242 jroman 371
   random vectors. In the case of EPSGDGetKrylovStart is PETSC_TRUE, the solver
1980 eromero 372
   gets the first vector provided by the user or, if not, a random vector,
373
   and expands the Krylov basis up to initialsize vectors.
374
 
375
   Collective on EPS
376
 
1994 eromero 377
   Input Parameters:
378
+  eps - the eigenproblem solver context
379
-  initialsize - non-zero positive integer indicating the number of vectors of
1980 eromero 380
   the initial searching subspace
381
 
382
   Options Database Key:
383
.  -eps_gd_initial_size - non-zero positive integer indicating the number of
384
    vectors of the initial searching subspace
385
 
386
   Level: advanced
387
 
2242 jroman 388
.seealso: EPSGDGetInitialSize(), EPSGDGetKrylovStart()
1980 eromero 389
@*/
390
PetscErrorCode EPSGDSetInitialSize(EPS eps,PetscInt initialsize)
391
{
2221 jroman 392
  PetscErrorCode ierr;
1980 eromero 393
 
394
  PetscFunctionBegin;
2213 jroman 395
  PetscValidHeaderSpecific(eps,EPS_CLASSID,1);
2221 jroman 396
  ierr = PetscTryMethod(eps,"EPSGDSetInitialSize_C",(EPS,PetscInt),(eps,initialsize));CHKERRQ(ierr);
1980 eromero 397
  PetscFunctionReturn(0);
398
}
399