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
1272 slepc 1
/*
2
     SVD routines for setting solver options.
1376 slepc 3
 
4
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1672 slepc 5
   SLEPc - Scalable Library for Eigenvalue Problem Computations
2116 eromero 6
   Copyright (c) 2002-2010, Universidad Politecnica de Valencia, Spain
1376 slepc 7
 
1672 slepc 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/>.
1376 slepc 21
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1272 slepc 22
*/
1376 slepc 23
 
2284 jroman 24
#include <private/svdimpl.h>      /*I "slepcsvd.h" I*/
1272 slepc 25
 
26
#undef __FUNCT__  
27
#define __FUNCT__ "SVDSetTransposeMode"
1333 slepc 28
/*@
1272 slepc 29
   SVDSetTransposeMode - Sets how to handle the transpose of the matrix
30
   associated with the singular value problem.
31
 
1704 jroman 32
   Collective on SVD
1272 slepc 33
 
34
   Input Parameters:
35
+  svd  - the singular value solver context
36
-  mode - how to compute the transpose, one of SVD_TRANSPOSE_EXPLICIT
1402 slepc 37
          or SVD_TRANSPOSE_IMPLICIT (see notes below)
1272 slepc 38
 
39
   Options Database Key:
40
.  -svd_transpose_mode <mode> - Indicates the mode flag, where <mode>
1402 slepc 41
    is one of 'explicit' or 'implicit'.
1272 slepc 42
 
43
   Notes:
44
   In the SVD_TRANSPOSE_EXPLICIT mode, the transpose of the matrix is
45
   explicitly built.
46
 
1402 slepc 47
   The option SVD_TRANSPOSE_IMPLICIT does not build the transpose, but
1272 slepc 48
   handles it implicitly via MatMultTranspose() operations. This is
49
   likely to be more inefficient than SVD_TRANSPOSE_EXPLICIT, both in
50
   sequential and in parallel, but requires less storage.
51
 
52
   The default is SVD_TRANSPOSE_EXPLICIT if the matrix has defined the
1402 slepc 53
   MatTranspose operation, and SVD_TRANSPOSE_IMPLICIT otherwise.
1272 slepc 54
 
55
   Level: advanced
56
 
1403 slepc 57
.seealso: SVDGetTransposeMode(), SVDSolve(), SVDSetOperator(),
1364 slepc 58
   SVDGetOperator(), SVDTransposeMode
1272 slepc 59
@*/
60
PetscErrorCode SVDSetTransposeMode(SVD svd,SVDTransposeMode mode)
61
{
62
  PetscFunctionBegin;
2213 jroman 63
  PetscValidHeaderSpecific(svd,SVD_CLASSID,1);
1825 jroman 64
  if (mode == PETSC_DEFAULT || mode == PETSC_DECIDE) mode = (SVDTransposeMode)PETSC_DECIDE;
65
  else switch (mode) {
1272 slepc 66
    case SVD_TRANSPOSE_EXPLICIT:
1283 slepc 67
    case SVD_TRANSPOSE_IMPLICIT:
1272 slepc 68
      svd->transmode = mode;
69
      svd->setupcalled = 0;
70
      break;
71
    default:
2214 jroman 72
      SETERRQ(((PetscObject)svd)->comm,PETSC_ERR_ARG_OUTOFRANGE,"Invalid transpose mode");
1272 slepc 73
  }
74
  PetscFunctionReturn(0);
75
}
76
 
77
#undef __FUNCT__  
78
#define __FUNCT__ "SVDGetTransposeMode"
1333 slepc 79
/*@C
1704 jroman 80
   SVDGetTransposeMode - Gets the mode used to compute the transpose
1272 slepc 81
   of the matrix associated with the singular value problem.
82
 
83
   Not collective
84
 
85
   Input Parameter:
1405 slepc 86
.  svd  - the singular value solver context
1272 slepc 87
 
88
   Output paramter:
1405 slepc 89
.  mode - how to compute the transpose, one of SVD_TRANSPOSE_EXPLICIT
1402 slepc 90
          or SVD_TRANSPOSE_IMPLICIT
1272 slepc 91
 
92
   Level: advanced
93
 
1403 slepc 94
.seealso: SVDSetTransposeMode(), SVDSolve(), SVDSetOperator(),
1364 slepc 95
   SVDGetOperator(), SVDTransposeMode
1272 slepc 96
@*/
97
PetscErrorCode SVDGetTransposeMode(SVD svd,SVDTransposeMode *mode)
98
{
99
  PetscFunctionBegin;
2213 jroman 100
  PetscValidHeaderSpecific(svd,SVD_CLASSID,1);
1272 slepc 101
  PetscValidPointer(mode,2);
102
  *mode = svd->transmode;
103
  PetscFunctionReturn(0);
104
}
105
 
106
#undef __FUNCT__  
107
#define __FUNCT__ "SVDSetTolerances"
108
/*@
109
   SVDSetTolerances - Sets the tolerance and maximum
110
   iteration count used by the default SVD convergence testers.
111
 
112
   Collective on SVD
113
 
114
   Input Parameters:
1405 slepc 115
+  svd - the singular value solver context
1272 slepc 116
.  tol - the convergence tolerance
117
-  maxits - maximum number of iterations to use
118
 
119
   Options Database Keys:
120
+  -svd_tol <tol> - Sets the convergence tolerance
121
-  -svd_max_it <maxits> - Sets the maximum number of iterations allowed
1283 slepc 122
   (use PETSC_DECIDE to compute an educated guess based on basis and matrix sizes)
1272 slepc 123
 
124
   Notes:
125
   Use PETSC_IGNORE to retain the previous value of any parameter.
126
 
127
   Level: intermediate
128
 
129
.seealso: SVDGetTolerances()
130
@*/
1504 slepc 131
PetscErrorCode SVDSetTolerances(SVD svd,PetscReal tol,PetscInt maxits)
1272 slepc 132
{
133
  PetscFunctionBegin;
2213 jroman 134
  PetscValidHeaderSpecific(svd,SVD_CLASSID,1);
1272 slepc 135
  if (tol != PETSC_IGNORE) {
1283 slepc 136
    if (tol == PETSC_DEFAULT) {
137
      tol = 1e-7;
138
    } else {
2214 jroman 139
      if (tol < 0.0) SETERRQ(((PetscObject)svd)->comm,PETSC_ERR_ARG_OUTOFRANGE,"Illegal value of tol. Must be > 0");
1283 slepc 140
      svd->tol = tol;
141
    }
1272 slepc 142
  }
143
  if (maxits != PETSC_IGNORE) {
1283 slepc 144
    if (maxits == PETSC_DEFAULT || maxits == PETSC_DECIDE) {
1594 slepc 145
      svd->max_it = 0;
1272 slepc 146
      svd->setupcalled = 0;
147
    } else {
2214 jroman 148
      if (maxits < 0) SETERRQ(((PetscObject)svd)->comm,PETSC_ERR_ARG_OUTOFRANGE,"Illegal value of maxits. Must be > 0");
1283 slepc 149
      svd->max_it = maxits;
1272 slepc 150
    }
151
  }
152
  PetscFunctionReturn(0);
153
}
154
 
155
#undef __FUNCT__  
156
#define __FUNCT__ "SVDGetTolerances"
157
/*@
158
   SVDGetTolerances - Gets the tolerance and maximum
159
   iteration count used by the default SVD convergence tests.
160
 
161
   Not Collective
162
 
163
   Input Parameter:
164
.  svd - the singular value solver context
165
 
166
   Output Parameters:
167
+  tol - the convergence tolerance
168
-  maxits - maximum number of iterations
169
 
170
   Notes:
171
   The user can specify PETSC_NULL for any parameter that is not needed.
172
 
173
   Level: intermediate
174
 
175
.seealso: SVDSetTolerances()
176
@*/
1504 slepc 177
PetscErrorCode SVDGetTolerances(SVD svd,PetscReal *tol,PetscInt *maxits)
1272 slepc 178
{
179
  PetscFunctionBegin;
2213 jroman 180
  PetscValidHeaderSpecific(svd,SVD_CLASSID,1);
1272 slepc 181
  if (tol)    *tol    = svd->tol;
182
  if (maxits) *maxits = svd->max_it;
183
  PetscFunctionReturn(0);
184
}
185
 
186
#undef __FUNCT__  
187
#define __FUNCT__ "SVDSetDimensions"
188
/*@
189
   SVDSetDimensions - Sets the number of singular values to compute
190
   and the dimension of the subspace.
191
 
192
   Collective on SVD
193
 
194
   Input Parameters:
1311 slepc 195
+  svd - the singular value solver context
1272 slepc 196
.  nsv - number of singular values to compute
1575 slepc 197
.  ncv - the maximum dimension of the subspace to be used by the solver
198
-  mpd - the maximum dimension allowed for the projected problem
1272 slepc 199
 
200
   Options Database Keys:
201
+  -svd_nsv <nsv> - Sets the number of singular values
1575 slepc 202
.  -svd_ncv <ncv> - Sets the dimension of the subspace
203
-  -svd_mpd <mpd> - Sets the maximum projected dimension
1272 slepc 204
 
205
   Notes:
206
   Use PETSC_IGNORE to retain the previous value of any parameter.
207
 
1575 slepc 208
   Use PETSC_DECIDE for ncv and mpd to assign a reasonably good value, which is
1283 slepc 209
   dependent on the solution method and the number of singular values required.
1272 slepc 210
 
1575 slepc 211
   The parameters ncv and mpd are intimately related, so that the user is advised
212
   to set one of them at most. Normal usage is the following:
2242 jroman 213
   (a) In cases where nsv is small, the user sets ncv (a reasonable default is 2*nsv).
214
   (b) In cases where nsv is large, the user sets mpd.
1575 slepc 215
 
216
   The value of ncv should always be between nsv and (nsv+mpd), typically
217
   ncv=nsv+mpd. If nev is not too large, mpd=nsv is a reasonable choice, otherwise
218
   a smaller value should be used.
219
 
1272 slepc 220
   Level: intermediate
221
 
222
.seealso: SVDGetDimensions()
223
@*/
1575 slepc 224
PetscErrorCode SVDSetDimensions(SVD svd,PetscInt nsv,PetscInt ncv,PetscInt mpd)
1272 slepc 225
{
226
  PetscFunctionBegin;
2213 jroman 227
  PetscValidHeaderSpecific(svd,SVD_CLASSID,1);
1272 slepc 228
  if (nsv != PETSC_IGNORE) {
2214 jroman 229
    if (nsv<1) SETERRQ(((PetscObject)svd)->comm,PETSC_ERR_ARG_OUTOFRANGE,"Illegal value of nsv. Must be > 0");
1272 slepc 230
    svd->nsv = nsv;
231
  }
232
  if (ncv != PETSC_IGNORE) {
1283 slepc 233
    if (ncv == PETSC_DEFAULT || ncv == PETSC_DECIDE) {
1594 slepc 234
      svd->ncv = 0;
1283 slepc 235
    } else {
2214 jroman 236
      if (ncv<1) SETERRQ(((PetscObject)svd)->comm,PETSC_ERR_ARG_OUTOFRANGE,"Illegal value of ncv. Must be > 0");
1283 slepc 237
      svd->ncv = ncv;
238
    }
1272 slepc 239
    svd->setupcalled = 0;
240
  }
1575 slepc 241
  if( mpd != PETSC_IGNORE ) {
242
    if (mpd == PETSC_DECIDE || mpd == PETSC_DEFAULT) {
1594 slepc 243
      svd->mpd = 0;
1575 slepc 244
    } else {
2214 jroman 245
      if (mpd<1) SETERRQ(((PetscObject)svd)->comm,PETSC_ERR_ARG_OUTOFRANGE,"Illegal value of mpd. Must be > 0");
1575 slepc 246
      svd->mpd = mpd;
247
    }
248
  }
1272 slepc 249
  PetscFunctionReturn(0);
250
}
251
 
252
#undef __FUNCT__  
253
#define __FUNCT__ "SVDGetDimensions"
254
/*@
255
   SVDGetDimensions - Gets the number of singular values to compute
256
   and the dimension of the subspace.
257
 
258
   Not Collective
259
 
260
   Input Parameter:
261
.  svd - the singular value context
262
 
263
   Output Parameters:
264
+  nsv - number of singular values to compute
1575 slepc 265
.  ncv - the maximum dimension of the subspace to be used by the solver
266
-  mpd - the maximum dimension allowed for the projected problem
1272 slepc 267
 
268
   Notes:
269
   The user can specify PETSC_NULL for any parameter that is not needed.
270
 
271
   Level: intermediate
272
 
273
.seealso: SVDSetDimensions()
274
@*/
1575 slepc 275
PetscErrorCode SVDGetDimensions(SVD svd,PetscInt *nsv,PetscInt *ncv,PetscInt *mpd)
1272 slepc 276
{
277
  PetscFunctionBegin;
2213 jroman 278
  PetscValidHeaderSpecific(svd,SVD_CLASSID,1);
1272 slepc 279
  if (nsv) *nsv = svd->nsv;
280
  if (ncv) *ncv = svd->ncv;
1575 slepc 281
  if (mpd) *mpd = svd->mpd;
1272 slepc 282
  PetscFunctionReturn(0);
283
}
284
 
285
#undef __FUNCT__  
286
#define __FUNCT__ "SVDSetWhichSingularTriplets"
287
/*@
288
    SVDSetWhichSingularTriplets - Specifies which singular triplets are
289
    to be sought.
290
 
291
    Collective on SVD
292
 
293
    Input Parameter:
294
.   svd - singular value solver context obtained from SVDCreate()
295
 
296
    Output Parameter:
297
.   which - which singular triplets are to be sought
298
 
299
    Possible values:
300
    The parameter 'which' can have one of these values:
301
 
302
+     SVD_LARGEST  - largest singular values
303
-     SVD_SMALLEST - smallest singular values
304
 
305
    Options Database Keys:
1277 slepc 306
+   -svd_largest  - Sets largest singular values
307
-   -svd_smallest - Sets smallest singular values
1272 slepc 308
 
309
    Level: intermediate
310
 
1364 slepc 311
.seealso: SVDGetWhichSingularTriplets(), SVDWhich
1272 slepc 312
@*/
313
PetscErrorCode SVDSetWhichSingularTriplets(SVD svd,SVDWhich which)
314
{
315
  PetscFunctionBegin;
2213 jroman 316
  PetscValidHeaderSpecific(svd,SVD_CLASSID,1);
1272 slepc 317
  switch (which) {
318
    case SVD_LARGEST:
319
    case SVD_SMALLEST:
1406 slepc 320
      if (svd->which != which) {
321
        svd->setupcalled = 0;
322
        svd->which = which;
323
      }
1272 slepc 324
      break;
325
  default:
2214 jroman 326
    SETERRQ(((PetscObject)svd)->comm,PETSC_ERR_ARG_OUTOFRANGE,"Invalid 'which' parameter");    
1272 slepc 327
  }
328
  PetscFunctionReturn(0);
329
}
330
 
331
#undef __FUNCT__  
332
#define __FUNCT__ "SVDGetWhichSingularTriplets"
333
/*@C
1333 slepc 334
    SVDGetWhichSingularTriplets - Returns which singular triplets are
1272 slepc 335
    to be sought.
336
 
337
    Not Collective
338
 
339
    Input Parameter:
340
.   svd - singular value solver context obtained from SVDCreate()
341
 
342
    Output Parameter:
343
.   which - which singular triplets are to be sought
344
 
345
    Notes:
346
    See SVDSetWhichSingularTriplets() for possible values of which
347
 
348
    Level: intermediate
349
 
1364 slepc 350
.seealso: SVDSetWhichSingularTriplets(), SVDWhich
1272 slepc 351
@*/
352
PetscErrorCode SVDGetWhichSingularTriplets(SVD svd,SVDWhich *which)
353
{
354
  PetscFunctionBegin;
2213 jroman 355
  PetscValidHeaderSpecific(svd,SVD_CLASSID,1);
1272 slepc 356
  PetscValidPointer(which,2);
357
  *which = svd->which;
358
  PetscFunctionReturn(0);
359
}
360
 
361
#undef __FUNCT__  
362
#define __FUNCT__ "SVDSetFromOptions"
363
/*@
364
   SVDSetFromOptions - Sets SVD options from the options database.
365
   This routine must be called before SVDSetUp() if the user is to be
366
   allowed to set the solver type.
367
 
368
   Collective on SVD
369
 
370
   Input Parameters:
371
.  svd - the singular value solver context
372
 
373
   Notes:  
374
   To see all options, run your program with the -help option.
375
 
376
   Level: beginner
377
 
378
.seealso:
379
@*/
380
PetscErrorCode SVDSetFromOptions(SVD svd)
381
{
2317 jroman 382
  PetscErrorCode          ierr;
383
  char                    type[256],monfilename[PETSC_MAX_PATH_LEN];
384
  PetscBool               flg;
385
  const char              *mode_list[2] = { "explicit", "implicit" };
386
  PetscInt                i,j,k;
387
  PetscReal               r;
1532 slepc 388
  PetscViewerASCIIMonitor monviewer;
2317 jroman 389
  SlepcConvMonitor        ctx;
1272 slepc 390
 
391
  PetscFunctionBegin;
2213 jroman 392
  PetscValidHeaderSpecific(svd,SVD_CLASSID,1);
1272 slepc 393
  svd->setupcalled = 0;
1422 slepc 394
  ierr = PetscOptionsBegin(((PetscObject)svd)->comm,((PetscObject)svd)->prefix,"Singular Value Solver (SVD) Options","SVD");CHKERRQ(ierr);
1272 slepc 395
 
1422 slepc 396
  ierr = PetscOptionsList("-svd_type","Singular Value Solver method","SVDSetType",SVDList,(char*)(((PetscObject)svd)->type_name?((PetscObject)svd)->type_name:SVDCROSS),type,256,&flg);CHKERRQ(ierr);
1272 slepc 397
  if (flg) {
398
    ierr = SVDSetType(svd,type);CHKERRQ(ierr);
1422 slepc 399
  } else if (!((PetscObject)svd)->type_name) {
1342 slepc 400
    ierr = SVDSetType(svd,SVDCROSS);CHKERRQ(ierr);
1272 slepc 401
  }
402
 
403
  ierr = PetscOptionsName("-svd_view","Print detailed information on solver used","SVDView",0);CHKERRQ(ierr);
404
 
1283 slepc 405
  ierr = PetscOptionsEList("-svd_transpose_mode","Transpose SVD mode","SVDSetTransposeMode",mode_list,2,svd->transmode == PETSC_DECIDE ? "decide" : mode_list[svd->transmode],&i,&flg);CHKERRQ(ierr);
1272 slepc 406
  if (flg) {
407
    ierr = SVDSetTransposeMode(svd,(SVDTransposeMode)i);CHKERRQ(ierr);
408
  }  
409
 
410
  r = i = PETSC_IGNORE;
1283 slepc 411
  ierr = PetscOptionsInt("-svd_max_it","Maximum number of iterations","SVDSetTolerances",svd->max_it,&i,PETSC_NULL);CHKERRQ(ierr);
412
  ierr = PetscOptionsReal("-svd_tol","Tolerance","SVDSetTolerances",svd->tol,&r,PETSC_NULL);CHKERRQ(ierr);
413
  ierr = SVDSetTolerances(svd,r,i);CHKERRQ(ierr);
1272 slepc 414
 
1592 slepc 415
  i = j = k = PETSC_IGNORE;
1575 slepc 416
  ierr = PetscOptionsInt("-svd_nsv","Number of singular values to compute","SVDSetDimensions",svd->nsv,&i,PETSC_NULL);CHKERRQ(ierr);
1283 slepc 417
  ierr = PetscOptionsInt("-svd_ncv","Number of basis vectors","SVDSetDimensions",svd->ncv,&j,PETSC_NULL);CHKERRQ(ierr);
1575 slepc 418
  ierr = PetscOptionsInt("-svd_mpd","Maximum dimension of projected problem","SVDSetDimensions",svd->mpd,&k,PETSC_NULL);CHKERRQ(ierr);
419
  ierr = SVDSetDimensions(svd,i,j,k);CHKERRQ(ierr);
1272 slepc 420
 
2216 jroman 421
  ierr = PetscOptionsBoolGroupBegin("-svd_largest","compute largest singular values","SVDSetWhichSingularTriplets",&flg);CHKERRQ(ierr);
1277 slepc 422
  if (flg) { ierr = SVDSetWhichSingularTriplets(svd,SVD_LARGEST);CHKERRQ(ierr); }
2216 jroman 423
  ierr = PetscOptionsBoolGroupEnd("-svd_smallest","compute smallest singular values","SVDSetWhichSingularTriplets",&flg);CHKERRQ(ierr);
1277 slepc 424
  if (flg) { ierr = SVDSetWhichSingularTriplets(svd,SVD_SMALLEST);CHKERRQ(ierr); }
425
 
1713 antodo 426
  flg = PETSC_FALSE;
2216 jroman 427
  ierr = PetscOptionsBool("-svd_monitor_cancel","Remove any hardwired monitor routines","SVDMonitorCancel",flg,&flg,PETSC_NULL);CHKERRQ(ierr);
1288 slepc 428
  if (flg) {
1331 slepc 429
    ierr = SVDMonitorCancel(svd);CHKERRQ(ierr);
1288 slepc 430
  }
431
 
2054 eromero 432
  ierr = PetscOptionsString("-svd_monitor_all","Monitor approximate singular values and error estimates","SVDMonitorSet","stdout",monfilename,PETSC_MAX_PATH_LEN,&flg);CHKERRQ(ierr);
1288 slepc 433
  if (flg) {
1532 slepc 434
    ierr = PetscViewerASCIIMonitorCreate(((PetscObject)svd)->comm,monfilename,((PetscObject)svd)->tablevel,&monviewer);CHKERRQ(ierr);
2054 eromero 435
    ierr = SVDMonitorSet(svd,SVDMonitorAll,monviewer,(PetscErrorCode (*)(void*))PetscViewerASCIIMonitorDestroy);CHKERRQ(ierr);
436
    ierr = SVDSetTrackAll(svd,PETSC_TRUE);CHKERRQ(ierr);
1288 slepc 437
  }
1721 antodo 438
  ierr = PetscOptionsString("-svd_monitor_conv","Monitor approximate singular values and error estimates as they converge","SVDMonitorSet","stdout",monfilename,PETSC_MAX_PATH_LEN,&flg);CHKERRQ(ierr);
439
  if (flg) {
2311 jroman 440
      ierr = PetscNew(struct _n_SlepcConvMonitor,&ctx);CHKERRQ(ierr);
1951 jroman 441
      ierr = PetscViewerASCIIMonitorCreate(((PetscObject)svd)->comm,monfilename,((PetscObject)svd)->tablevel,&ctx->viewer);CHKERRQ(ierr);
2314 jroman 442
      ierr = SVDMonitorSet(svd,SVDMonitorConverged,ctx,(PetscErrorCode (*)(void*))SlepcConvMonitorDestroy);CHKERRQ(ierr);
1721 antodo 443
  }
2054 eromero 444
  ierr = PetscOptionsString("-svd_monitor","Monitor first unconverged approximate singular value and error estimate","SVDMonitorSet","stdout",monfilename,PETSC_MAX_PATH_LEN,&flg);CHKERRQ(ierr);
1721 antodo 445
  if (flg) {
446
    ierr = PetscViewerASCIIMonitorCreate(((PetscObject)svd)->comm,monfilename,((PetscObject)svd)->tablevel,&monviewer);CHKERRQ(ierr);
447
    ierr = SVDMonitorSet(svd,SVDMonitorFirst,monviewer,(PetscErrorCode (*)(void*))PetscViewerASCIIMonitorDestroy);CHKERRQ(ierr);
448
  }
1713 antodo 449
  flg = PETSC_FALSE;
2216 jroman 450
  ierr = PetscOptionsBool("-svd_monitor_draw","Monitor first unconverged approximate singular value and error estimate graphically","SVDMonitorSet",flg,&flg,PETSC_NULL);CHKERRQ(ierr);
1288 slepc 451
  if (flg) {
1331 slepc 452
    ierr = SVDMonitorSet(svd,SVDMonitorLG,PETSC_NULL,PETSC_NULL);CHKERRQ(ierr);
1288 slepc 453
  }
2054 eromero 454
  flg = PETSC_FALSE;
2216 jroman 455
  ierr = PetscOptionsBool("-svd_monitor_draw_all","Monitor error estimates graphically","SVDMonitorSet",flg,&flg,PETSC_NULL);CHKERRQ(ierr);
2054 eromero 456
  if (flg) {
457
    ierr = SVDMonitorSet(svd,SVDMonitorLGAll,PETSC_NULL,PETSC_NULL);CHKERRQ(ierr);
458
    ierr = SVDSetTrackAll(svd,PETSC_TRUE);CHKERRQ(ierr);
459
  }
1288 slepc 460
 
1272 slepc 461
  ierr = PetscOptionsEnd();CHKERRQ(ierr);
1302 slepc 462
  ierr = IPSetFromOptions(svd->ip);CHKERRQ(ierr);
1272 slepc 463
  if (svd->ops->setfromoptions) {
464
    ierr = (*svd->ops->setfromoptions)(svd);CHKERRQ(ierr);
465
  }
466
  PetscFunctionReturn(0);
467
}
1309 slepc 468
 
469
#undef __FUNCT__  
2054 eromero 470
#define __FUNCT__ "SVDSetTrackAll"
471
/*@
2317 jroman 472
   SVDSetTrackAll - Specifies if the solver must compute the residual norm of all
473
   approximate singular value or not.
2054 eromero 474
 
2317 jroman 475
   Collective on SVD
2054 eromero 476
 
2317 jroman 477
   Input Parameters:
478
+  svd      - the singular value solver context
479
-  trackall - whether to compute all residuals or not
2054 eromero 480
 
2317 jroman 481
   Notes:
482
   If the user sets trackall=PETSC_TRUE then the solver computes (or estimates)
483
   the residual norm for each singular value approximation. Computing the residual is
484
   usually an expensive operation and solvers commonly compute only the residual
485
   associated to the first unconverged singular value.
2054 eromero 486
 
2317 jroman 487
   The options '-svd_monitor_all' and '-svd_monitor_draw_all' automatically
488
   activate this option.
2054 eromero 489
 
2317 jroman 490
   Level: intermediate
2054 eromero 491
 
492
.seealso: SVDGetTrackAll()
493
@*/
2216 jroman 494
PetscErrorCode SVDSetTrackAll(SVD svd,PetscBool trackall)
2054 eromero 495
{
496
  PetscFunctionBegin;
2213 jroman 497
  PetscValidHeaderSpecific(svd,SVD_CLASSID,1);
2054 eromero 498
  svd->trackall = trackall;
499
  PetscFunctionReturn(0);
500
}
501
 
502
#undef __FUNCT__  
503
#define __FUNCT__ "SVDGetTrackAll"
504
/*@
2317 jroman 505
   SVDGetTrackAll - Returns the flag indicating whether all residual norms must
506
   be computed or not.
2054 eromero 507
 
2317 jroman 508
   Not Collective
2054 eromero 509
 
2317 jroman 510
   Input Parameter:
511
.  svd - the singular value solver context
2054 eromero 512
 
2317 jroman 513
   Output Parameter:
514
.  trackall - the returned flag
2054 eromero 515
 
2317 jroman 516
   Level: intermediate
2054 eromero 517
 
518
.seealso: SVDSetTrackAll()
519
@*/
2216 jroman 520
PetscErrorCode SVDGetTrackAll(SVD svd,PetscBool *trackall)
2054 eromero 521
{
522
  PetscFunctionBegin;
2213 jroman 523
  PetscValidHeaderSpecific(svd,SVD_CLASSID,1);
2054 eromero 524
  PetscValidPointer(trackall,2);
525
  *trackall = svd->trackall;
526
  PetscFunctionReturn(0);
527
}
528
 
529
 
530
#undef __FUNCT__  
1309 slepc 531
#define __FUNCT__ "SVDSetOptionsPrefix"
532
/*@C
533
   SVDSetOptionsPrefix - Sets the prefix used for searching for all
534
   SVD options in the database.
535
 
536
   Collective on SVD
537
 
538
   Input Parameters:
539
+  svd - the singular value solver context
540
-  prefix - the prefix string to prepend to all SVD option requests
541
 
542
   Notes:
543
   A hyphen (-) must NOT be given at the beginning of the prefix name.
544
   The first character of all runtime options is AUTOMATICALLY the
545
   hyphen.
546
 
547
   For example, to distinguish between the runtime options for two
548
   different SVD contexts, one could call
549
.vb
550
      SVDSetOptionsPrefix(svd1,"svd1_")
551
      SVDSetOptionsPrefix(svd2,"svd2_")
552
.ve
553
 
554
   Level: advanced
555
 
556
.seealso: SVDAppendOptionsPrefix(), SVDGetOptionsPrefix()
557
@*/
558
PetscErrorCode SVDSetOptionsPrefix(SVD svd,const char *prefix)
559
{
560
  PetscErrorCode ierr;
2216 jroman 561
  PetscBool      flg1,flg2;
1316 slepc 562
  EPS            eps;
563
 
1309 slepc 564
  PetscFunctionBegin;
2213 jroman 565
  PetscValidHeaderSpecific(svd,SVD_CLASSID,1);
1309 slepc 566
  ierr = PetscObjectSetOptionsPrefix((PetscObject)svd,prefix);CHKERRQ(ierr);
1342 slepc 567
  ierr = PetscTypeCompare((PetscObject)svd,SVDCROSS,&flg1);CHKERRQ(ierr);
568
  ierr = PetscTypeCompare((PetscObject)svd,SVDCYCLIC,&flg2);CHKERRQ(ierr);
569
  if (flg1) {
570
    ierr = SVDCrossGetEPS(svd,&eps);CHKERRQ(ierr);
571
  } else if (flg2) {
572
      ierr = SVDCyclicGetEPS(svd,&eps);CHKERRQ(ierr);
573
  }
574
  if (flg1 || flg2) {
1316 slepc 575
    ierr = EPSSetOptionsPrefix(eps,prefix);CHKERRQ(ierr);
576
    ierr = EPSAppendOptionsPrefix(eps,"svd_");CHKERRQ(ierr);
577
  }
1345 slepc 578
  ierr = IPSetOptionsPrefix(svd->ip,prefix);CHKERRQ(ierr);
579
  ierr = IPAppendOptionsPrefix(svd->ip,"svd_");CHKERRQ(ierr);
1309 slepc 580
  PetscFunctionReturn(0);  
581
}
582
 
583
#undef __FUNCT__  
584
#define __FUNCT__ "SVDAppendOptionsPrefix"
585
/*@C
586
   SVDAppendOptionsPrefix - Appends to the prefix used for searching for all
587
   SVD options in the database.
588
 
589
   Collective on SVD
590
 
591
   Input Parameters:
1311 slepc 592
+  svd - the singular value solver context
1309 slepc 593
-  prefix - the prefix string to prepend to all SVD option requests
594
 
595
   Notes:
596
   A hyphen (-) must NOT be given at the beginning of the prefix name.
597
   The first character of all runtime options is AUTOMATICALLY the hyphen.
598
 
599
   Level: advanced
600
 
601
.seealso: SVDSetOptionsPrefix(), SVDGetOptionsPrefix()
602
@*/
603
PetscErrorCode SVDAppendOptionsPrefix(SVD svd,const char *prefix)
604
{
605
  PetscErrorCode ierr;
2216 jroman 606
  PetscBool      flg1,flg2;
1316 slepc 607
  EPS            eps;
608
 
1309 slepc 609
  PetscFunctionBegin;
2213 jroman 610
  PetscValidHeaderSpecific(svd,SVD_CLASSID,1);
1309 slepc 611
  ierr = PetscObjectAppendOptionsPrefix((PetscObject)svd,prefix);CHKERRQ(ierr);
1324 slepc 612
  ierr = PetscTypeCompare((PetscObject)svd,SVDCROSS,&flg1);CHKERRQ(ierr);
613
  ierr = PetscTypeCompare((PetscObject)svd,SVDCYCLIC,&flg2);CHKERRQ(ierr);
614
  if (flg1) {
615
    ierr = SVDCrossGetEPS(svd,&eps);CHKERRQ(ierr);
616
  } else if (flg2) {
617
    ierr = SVDCyclicGetEPS(svd,&eps);CHKERRQ(ierr);
618
  }
1342 slepc 619
  if (flg1 || flg2) {
1422 slepc 620
    ierr = EPSSetOptionsPrefix(eps,((PetscObject)svd)->prefix);CHKERRQ(ierr);
1316 slepc 621
    ierr = EPSAppendOptionsPrefix(eps,"svd_");CHKERRQ(ierr);
622
  }
1422 slepc 623
  ierr = IPSetOptionsPrefix(svd->ip,((PetscObject)svd)->prefix);CHKERRQ(ierr);
1345 slepc 624
  ierr = IPAppendOptionsPrefix(svd->ip,"svd_");CHKERRQ(ierr);
1309 slepc 625
  PetscFunctionReturn(0);
626
}
627
 
628
#undef __FUNCT__  
629
#define __FUNCT__ "SVDGetOptionsPrefix"
630
/*@C
631
   SVDGetOptionsPrefix - Gets the prefix used for searching for all
632
   SVD options in the database.
633
 
634
   Not Collective
635
 
636
   Input Parameters:
1311 slepc 637
.  svd - the singular value solver context
1309 slepc 638
 
639
   Output Parameters:
640
.  prefix - pointer to the prefix string used is returned
641
 
642
   Notes: On the fortran side, the user should pass in a string 'prefix' of
643
   sufficient length to hold the prefix.
644
 
645
   Level: advanced
646
 
647
.seealso: SVDSetOptionsPrefix(), SVDAppendOptionsPrefix()
648
@*/
649
PetscErrorCode SVDGetOptionsPrefix(SVD svd,const char *prefix[])
650
{
651
  PetscErrorCode ierr;
2317 jroman 652
 
1309 slepc 653
  PetscFunctionBegin;
2213 jroman 654
  PetscValidHeaderSpecific(svd,SVD_CLASSID,1);
1309 slepc 655
  PetscValidPointer(prefix,2);
656
  ierr = PetscObjectGetOptionsPrefix((PetscObject)svd,prefix);CHKERRQ(ierr);
657
  PetscFunctionReturn(0);
658
}
659