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