Subversion Repositories slepc-dev

Rev

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