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