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
6 dsic.upv.es!jroman 1
/*
2
    The ST (spectral transformation) interface routines, callable by users.
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
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
6 dsic.upv.es!jroman 22
*/
23
 
2283 jroman 24
#include <private/stimpl.h>            /*I "slepcst.h" I*/
6 dsic.upv.es!jroman 25
 
2317 jroman 26
PetscClassId     ST_CLASSID = 0;
27
PetscLogEvent    ST_SetUp = 0, ST_Apply = 0, ST_ApplyTranspose = 0;
2216 jroman 28
static PetscBool STPackageInitialized = PETSC_FALSE;
842 dsic.upv.es!antodo 29
 
6 dsic.upv.es!jroman 30
#undef __FUNCT__  
1851 antodo 31
#define __FUNCT__ "STFinalizePackage"
32
/*@C
2317 jroman 33
   STFinalizePackage - This function destroys everything in the Slepc interface
34
   to the ST package. It is called from SlepcFinalize().
1851 antodo 35
 
2317 jroman 36
   Level: developer
1851 antodo 37
 
1853 antodo 38
.seealso: SlepcFinalize()
1851 antodo 39
@*/
40
PetscErrorCode STFinalizePackage(void)
41
{
42
  PetscFunctionBegin;
43
  STPackageInitialized = PETSC_FALSE;
44
  STList               = 0;
45
  PetscFunctionReturn(0);
46
}
47
 
48
#undef __FUNCT__  
842 dsic.upv.es!antodo 49
#define __FUNCT__ "STInitializePackage"
50
/*@C
2317 jroman 51
   STInitializePackage - This function initializes everything in the ST package. It is called
52
   from PetscDLLibraryRegister() when using dynamic libraries, and on the first call to STCreate()
53
   when using static libraries.
842 dsic.upv.es!antodo 54
 
2317 jroman 55
   Input Parameter:
56
.  path - The dynamic library path, or PETSC_NULL
842 dsic.upv.es!antodo 57
 
2317 jroman 58
   Level: developer
842 dsic.upv.es!antodo 59
 
60
.seealso: SlepcInitialize()
61
@*/
2317 jroman 62
PetscErrorCode STInitializePackage(const char *path)
63
{
2216 jroman 64
  char           logList[256];
65
  char           *className;
66
  PetscBool      opt;
842 dsic.upv.es!antodo 67
  PetscErrorCode ierr;
68
 
69
  PetscFunctionBegin;
1851 antodo 70
  if (STPackageInitialized) PetscFunctionReturn(0);
71
  STPackageInitialized = PETSC_TRUE;
842 dsic.upv.es!antodo 72
  /* Register Classes */
2213 jroman 73
  ierr = PetscClassIdRegister("Spectral Transform",&ST_CLASSID);CHKERRQ(ierr);
842 dsic.upv.es!antodo 74
  /* Register Constructors */
75
  ierr = STRegisterAll(path);CHKERRQ(ierr);
76
  /* Register Events */
2213 jroman 77
  ierr = PetscLogEventRegister("STSetUp",ST_CLASSID,&ST_SetUp);CHKERRQ(ierr);
78
  ierr = PetscLogEventRegister("STApply",ST_CLASSID,&ST_Apply);CHKERRQ(ierr);
79
  ierr = PetscLogEventRegister("STApplyTranspose",ST_CLASSID,&ST_ApplyTranspose); CHKERRQ(ierr);
842 dsic.upv.es!antodo 80
  /* Process info exclusions */
2213 jroman 81
  ierr = PetscOptionsGetString(PETSC_NULL, "-info_exclude", logList, 256, &opt);CHKERRQ(ierr);
842 dsic.upv.es!antodo 82
  if (opt) {
83
    ierr = PetscStrstr(logList, "st", &className);CHKERRQ(ierr);
84
    if (className) {
2213 jroman 85
      ierr = PetscInfoDeactivateClass(ST_CLASSID);CHKERRQ(ierr);
842 dsic.upv.es!antodo 86
    }
87
  }
88
  /* Process summary exclusions */
89
  ierr = PetscOptionsGetString(PETSC_NULL, "-log_summary_exclude", logList, 256, &opt);CHKERRQ(ierr);
90
  if (opt) {
91
    ierr = PetscStrstr(logList, "st", &className);CHKERRQ(ierr);
92
    if (className) {
2213 jroman 93
      ierr = PetscLogEventDeactivateClass(ST_CLASSID);CHKERRQ(ierr);
842 dsic.upv.es!antodo 94
    }
95
  }
1851 antodo 96
  ierr = PetscRegisterFinalize(STFinalizePackage);CHKERRQ(ierr);
842 dsic.upv.es!antodo 97
  PetscFunctionReturn(0);
98
}
99
 
100
#undef __FUNCT__  
6 dsic.upv.es!jroman 101
#define __FUNCT__ "STDestroy"
2312 jroman 102
/*@C
6 dsic.upv.es!jroman 103
   STDestroy - Destroys ST context that was created with STCreate().
104
 
105
   Collective on ST
106
 
107
   Input Parameter:
108
.  st - the spectral transformation context
109
 
110
   Level: beginner
111
 
112
.seealso: STCreate(), STSetUp()
113
@*/
2312 jroman 114
PetscErrorCode STDestroy(ST *st)
6 dsic.upv.es!jroman 115
{
476 dsic.upv.es!antodo 116
  PetscErrorCode ierr;
6 dsic.upv.es!jroman 117
 
118
  PetscFunctionBegin;
2312 jroman 119
  if (!*st) PetscFunctionReturn(0);
120
  PetscValidHeaderSpecific(*st,ST_CLASSID,1);
121
  if (--((PetscObject)(*st))->refct > 0) { *st = 0; PetscFunctionReturn(0); }
122
  ierr = PetscObjectDepublish(*st);CHKERRQ(ierr);
123
  if ((*st)->ops->destroy) {
124
    ierr = (*(*st)->ops->destroy)(*st);CHKERRQ(ierr);
344 dsic.upv.es!antodo 125
  }
2312 jroman 126
  ierr = MatDestroy(&(*st)->A);CHKERRQ(ierr);
127
  ierr = MatDestroy(&(*st)->B);CHKERRQ(ierr);
128
  ierr = KSPDestroy(&(*st)->ksp);CHKERRQ(ierr);
129
  ierr = VecDestroy(&(*st)->w);CHKERRQ(ierr);
130
  ierr = VecDestroy(&(*st)->D);CHKERRQ(ierr);
131
  ierr = VecDestroy(&(*st)->wb);CHKERRQ(ierr);
132
  if ((*st)->shift_matrix != ST_MATMODE_INPLACE) {
133
    ierr = MatDestroy(&(*st)->mat);CHKERRQ(ierr);
134
  }
135
  ierr = PetscHeaderDestroy(st);CHKERRQ(ierr);
6 dsic.upv.es!jroman 136
  PetscFunctionReturn(0);
137
}
138
 
139
#undef __FUNCT__  
140
#define __FUNCT__ "STCreate"
141
/*@C
142
   STCreate - Creates a spectral transformation context.
143
 
144
   Collective on MPI_Comm
145
 
146
   Input Parameter:
147
.  comm - MPI communicator
148
 
149
   Output Parameter:
150
.  st - location to put the spectral transformation context
151
 
152
   Level: beginner
153
 
1364 slepc 154
.seealso: STSetUp(), STApply(), STDestroy(), ST
6 dsic.upv.es!jroman 155
@*/
476 dsic.upv.es!antodo 156
PetscErrorCode STCreate(MPI_Comm comm,ST *newst)
6 dsic.upv.es!jroman 157
{
476 dsic.upv.es!antodo 158
  PetscErrorCode ierr;
159
  ST             st;
812 dsic.upv.es!antodo 160
  const char     *prefix;
6 dsic.upv.es!jroman 161
 
162
  PetscFunctionBegin;
476 dsic.upv.es!antodo 163
  PetscValidPointer(newst,2);
6 dsic.upv.es!jroman 164
  *newst = 0;
165
 
2213 jroman 166
  ierr = PetscHeaderCreate(st,_p_ST,struct _STOps,ST_CLASSID,-1,"ST",comm,STDestroy,STView);CHKERRQ(ierr);
337 dsic.upv.es!antodo 167
  ierr = PetscMemzero(st->ops,sizeof(struct _STOps));CHKERRQ(ierr);
6 dsic.upv.es!jroman 168
 
169
  st->A                   = 0;
170
  st->B                   = 0;
110 dsic.upv.es!antodo 171
  st->sigma               = 0.0;
2074 jroman 172
  st->sigma_set           = PETSC_FALSE;
173
  st->defsigma            = 0.0;
6 dsic.upv.es!jroman 174
  st->data                = 0;
175
  st->setupcalled         = 0;
344 dsic.upv.es!antodo 176
  st->w                   = 0;
1804 jroman 177
  st->D                   = 0;
178
  st->wb                  = 0;
2309 jroman 179
  st->mat                 = 0;
1940 jroman 180
  st->shift_matrix        = ST_MATMODE_COPY;
344 dsic.upv.es!antodo 181
  st->str                 = DIFFERENT_NONZERO_PATTERN;
246 dsic.upv.es!antodo 182
 
1422 slepc 183
  ierr = KSPCreate(((PetscObject)st)->comm,&st->ksp);CHKERRQ(ierr);
246 dsic.upv.es!antodo 184
  ierr = STGetOptionsPrefix(st,&prefix);CHKERRQ(ierr);
185
  ierr = KSPSetOptionsPrefix(st->ksp,prefix);CHKERRQ(ierr);
186
  ierr = KSPAppendOptionsPrefix(st->ksp,"st_");CHKERRQ(ierr);
1568 slepc 187
  ierr = PetscObjectIncrementTabLevel((PetscObject)st->ksp,(PetscObject)st,1);CHKERRQ(ierr);
246 dsic.upv.es!antodo 188
 
6 dsic.upv.es!jroman 189
  *newst                  = st;
190
  PetscFunctionReturn(0);
191
}
192
 
193
#undef __FUNCT__  
194
#define __FUNCT__ "STSetOperators"
195
/*@
196
   STSetOperators - Sets the matrices associated with the eigenvalue problem.
197
 
198
   Collective on ST and Mat
199
 
200
   Input Parameters:
201
+  st - the spectral transformation context
202
.  A  - the matrix associated with the eigensystem
203
-  B  - the second matrix in the case of generalized eigenproblems
204
 
205
   Notes:
206
   To specify a standard eigenproblem, use PETSC_NULL for B.
207
 
208
   Level: intermediate
209
 
210
.seealso: STGetOperators()
211
 @*/
476 dsic.upv.es!antodo 212
PetscErrorCode STSetOperators(ST st,Mat A,Mat B)
6 dsic.upv.es!jroman 213
{
1563 slepc 214
  PetscErrorCode ierr;
2317 jroman 215
 
6 dsic.upv.es!jroman 216
  PetscFunctionBegin;
2213 jroman 217
  PetscValidHeaderSpecific(st,ST_CLASSID,1);
218
  PetscValidHeaderSpecific(A,MAT_CLASSID,2);
219
  if (B) PetscValidHeaderSpecific(B,MAT_CLASSID,3);
1014 slepc 220
  PetscCheckSameComm(st,1,A,2);
221
  if (B) PetscCheckSameComm(st,1,B,3);
1563 slepc 222
  ierr = PetscObjectReference((PetscObject)A);CHKERRQ(ierr);
2305 jroman 223
  ierr = MatDestroy(&st->A);CHKERRQ(ierr);
6 dsic.upv.es!jroman 224
  st->A = A;
1563 slepc 225
  if (B) { ierr = PetscObjectReference((PetscObject)B);CHKERRQ(ierr); }
2305 jroman 226
  ierr = MatDestroy(&st->B);CHKERRQ(ierr);
6 dsic.upv.es!jroman 227
  st->B = B;
228
  st->setupcalled = 0;
229
  PetscFunctionReturn(0);
230
}
231
 
232
#undef __FUNCT__  
233
#define __FUNCT__ "STGetOperators"
234
/*@C
235
   STGetOperators - Gets the matrices associated with the eigensystem.
236
 
237
   Not collective, though parallel Mats are returned if the ST is parallel
238
 
239
   Input Parameter:
240
.  st - the spectral transformation context
241
 
242
   Output Parameters:
243
.  A - the matrix associated with the eigensystem
244
-  B - the second matrix in the case of generalized eigenproblems
245
 
246
   Level: intermediate
247
 
248
.seealso: STSetOperators()
249
@*/
476 dsic.upv.es!antodo 250
PetscErrorCode STGetOperators(ST st,Mat *A,Mat *B)
6 dsic.upv.es!jroman 251
{
252
  PetscFunctionBegin;
2213 jroman 253
  PetscValidHeaderSpecific(st,ST_CLASSID,1);
6 dsic.upv.es!jroman 254
  if (A) *A = st->A;
255
  if (B) *B = st->B;
256
  PetscFunctionReturn(0);
257
}
258
 
259
#undef __FUNCT__  
260
#define __FUNCT__ "STSetShift"
261
/*@
1804 jroman 262
   STSetShift - Sets the shift associated with the spectral transformation.
6 dsic.upv.es!jroman 263
 
1804 jroman 264
   Collective on ST
6 dsic.upv.es!jroman 265
 
266
   Input Parameters:
267
+  st - the spectral transformation context
268
-  shift - the value of the shift
269
 
270
   Note:
271
   In some spectral transformations, changing the shift may have associated
272
   a lot of work, for example recomputing a factorization.
273
 
274
   Level: beginner
275
 
276
@*/
476 dsic.upv.es!antodo 277
PetscErrorCode STSetShift(ST st,PetscScalar shift)
6 dsic.upv.es!jroman 278
{
476 dsic.upv.es!antodo 279
  PetscErrorCode ierr;
6 dsic.upv.es!jroman 280
 
281
  PetscFunctionBegin;
2213 jroman 282
  PetscValidHeaderSpecific(st,ST_CLASSID,1);
2326 jroman 283
  PetscValidLogicalCollectiveScalar(st,shift,2);
6 dsic.upv.es!jroman 284
  if (st->sigma != shift) {
285
    if (st->ops->setshift) {
286
      ierr = (*st->ops->setshift)(st,shift); CHKERRQ(ierr);
287
    }
288
  }
289
  st->sigma = shift;
2074 jroman 290
  st->sigma_set = PETSC_TRUE;
6 dsic.upv.es!jroman 291
  PetscFunctionReturn(0);
292
}
293
 
294
#undef __FUNCT__  
295
#define __FUNCT__ "STGetShift"
296
/*@
297
   STGetShift - Gets the shift associated with the spectral transformation.
298
 
299
   Not collective
300
 
301
   Input Parameter:
302
.  st - the spectral transformation context
303
 
304
   Output Parameter:
305
.  shift - the value of the shift
306
 
307
   Level: beginner
308
 
309
@*/
476 dsic.upv.es!antodo 310
PetscErrorCode STGetShift(ST st,PetscScalar* shift)
6 dsic.upv.es!jroman 311
{
312
  PetscFunctionBegin;
2213 jroman 313
  PetscValidHeaderSpecific(st,ST_CLASSID,1);
2326 jroman 314
  PetscValidScalarPointer(shift,2);
2319 jroman 315
  *shift = st->sigma;
6 dsic.upv.es!jroman 316
  PetscFunctionReturn(0);
317
}
318
 
319
#undef __FUNCT__  
2074 jroman 320
#define __FUNCT__ "STSetDefaultShift"
321
/*@
322
   STSetDefaultShift - Sets the value of the shift that should be employed if
323
   the user did not specify one.
324
 
325
   Collective on ST
326
 
327
   Input Parameters:
328
+  st - the spectral transformation context
329
-  defaultshift - the default value of the shift
330
 
331
   Level: developer
332
 
333
@*/
334
PetscErrorCode STSetDefaultShift(ST st,PetscScalar defaultshift)
335
{
336
  PetscFunctionBegin;
2213 jroman 337
  PetscValidHeaderSpecific(st,ST_CLASSID,1);
2326 jroman 338
  PetscValidLogicalCollectiveScalar(st,defaultshift,2);
2074 jroman 339
  st->defsigma = defaultshift;
340
  PetscFunctionReturn(0);
341
}
342
 
343
#undef __FUNCT__  
1804 jroman 344
#define __FUNCT__ "STSetBalanceMatrix"
345
/*@
346
   STSetBalanceMatrix - Sets the diagonal matrix to be used for balancing.
347
 
348
   Collective on ST and Vec
349
 
350
   Input Parameters:
351
+  st - the spectral transformation context
352
-  D  - the diagonal matrix (represented as a vector)
353
 
354
   Notes:
355
   If this matrix is set, STApply will effectively apply D*OP*D^{-1}.
356
 
357
   Balancing is usually set via EPSSetBalance, but the advanced user may use
358
   this function to bypass the usual balancing methods.
359
 
360
   Level: developer
361
 
362
.seealso: EPSSetBalance(), STApply(), STGetBalanceMatrix()
363
@*/
364
PetscErrorCode STSetBalanceMatrix(ST st,Vec D)
365
{
366
  PetscErrorCode ierr;
367
 
368
  PetscFunctionBegin;
2213 jroman 369
  PetscValidHeaderSpecific(st,ST_CLASSID,1);
370
  PetscValidHeaderSpecific(D,VEC_CLASSID,2);
1804 jroman 371
  PetscCheckSameComm(st,1,D,2);
372
  ierr = PetscObjectReference((PetscObject)D);CHKERRQ(ierr);
2305 jroman 373
  ierr = VecDestroy(&st->D); CHKERRQ(ierr);
1804 jroman 374
  st->D = D;
375
  if (!st->wb) {
2317 jroman 376
    ierr = VecDuplicate(st->D,&st->wb);CHKERRQ(ierr);
1804 jroman 377
  }
378
  PetscFunctionReturn(0);
379
}
380
 
381
#undef __FUNCT__  
382
#define __FUNCT__ "STGetBalanceMatrix"
383
/*@
384
   STGetBalanceMatrix - Gets the balance matrix used by the spectral transformation.
385
 
386
   Not collective, but vector is shared by all processors that share the ST
387
 
388
   Input Parameter:
389
.  st - the spectral transformation context
390
 
391
   Output Parameter:
392
.  D  - the diagonal matrix (represented as a vector)
393
 
394
   Note:
395
   If the matrix was not set, a null pointer will be returned.
396
 
397
   Level: developer
398
 
399
.seealso: STSetBalanceMatrix()
400
@*/
401
PetscErrorCode STGetBalanceMatrix(ST st,Vec *D)
402
{
403
  PetscFunctionBegin;
2213 jroman 404
  PetscValidHeaderSpecific(st,ST_CLASSID,1);
1804 jroman 405
  PetscValidPointer(D,2);
406
  *D = st->D;
407
  PetscFunctionReturn(0);
408
}
409
 
410
#undef __FUNCT__  
6 dsic.upv.es!jroman 411
#define __FUNCT__ "STSetOptionsPrefix"
412
/*@C
413
   STSetOptionsPrefix - Sets the prefix used for searching for all
414
   ST options in the database.
415
 
416
   Collective on ST
417
 
418
   Input Parameters:
419
+  st     - the spectral transformation context
420
-  prefix - the prefix string to prepend to all ST option requests
421
 
422
   Notes:
423
   A hyphen (-) must NOT be given at the beginning of the prefix name.
424
   The first character of all runtime options is AUTOMATICALLY the
425
   hyphen.
426
 
427
   Level: advanced
428
 
429
.seealso: STAppendOptionsPrefix(), STGetOptionsPrefix()
430
@*/
1248 slepc 431
PetscErrorCode STSetOptionsPrefix(ST st,const char *prefix)
6 dsic.upv.es!jroman 432
{
476 dsic.upv.es!antodo 433
  PetscErrorCode ierr;
6 dsic.upv.es!jroman 434
 
435
  PetscFunctionBegin;
2213 jroman 436
  PetscValidHeaderSpecific(st,ST_CLASSID,1);
1248 slepc 437
  ierr = PetscObjectSetOptionsPrefix((PetscObject)st,prefix);CHKERRQ(ierr);
438
  ierr = KSPSetOptionsPrefix(st->ksp,prefix);CHKERRQ(ierr);
439
  ierr = KSPAppendOptionsPrefix(st->ksp,"st_");CHKERRQ(ierr);
6 dsic.upv.es!jroman 440
  PetscFunctionReturn(0);
441
}
442
 
443
#undef __FUNCT__  
444
#define __FUNCT__ "STAppendOptionsPrefix"
445
/*@C
446
   STAppendOptionsPrefix - Appends to the prefix used for searching for all
447
   ST options in the database.
448
 
449
   Collective on ST
450
 
451
   Input Parameters:
452
+  st     - the spectral transformation context
453
-  prefix - the prefix string to prepend to all ST option requests
454
 
455
   Notes:
456
   A hyphen (-) must NOT be given at the beginning of the prefix name.
457
   The first character of all runtime options is AUTOMATICALLY the
458
   hyphen.
459
 
460
   Level: advanced
461
 
462
.seealso: STSetOptionsPrefix(), STGetOptionsPrefix()
463
@*/
1248 slepc 464
PetscErrorCode STAppendOptionsPrefix(ST st,const char *prefix)
6 dsic.upv.es!jroman 465
{
476 dsic.upv.es!antodo 466
  PetscErrorCode ierr;
6 dsic.upv.es!jroman 467
 
468
  PetscFunctionBegin;
2213 jroman 469
  PetscValidHeaderSpecific(st,ST_CLASSID,1);
1248 slepc 470
  ierr = PetscObjectAppendOptionsPrefix((PetscObject)st,prefix);CHKERRQ(ierr);
1422 slepc 471
  ierr = KSPSetOptionsPrefix(st->ksp,((PetscObject)st)->prefix);CHKERRQ(ierr);
1248 slepc 472
  ierr = KSPAppendOptionsPrefix(st->ksp,"st_");CHKERRQ(ierr);
6 dsic.upv.es!jroman 473
  PetscFunctionReturn(0);
474
}
475
 
476
#undef __FUNCT__  
477
#define __FUNCT__ "STGetOptionsPrefix"
478
/*@C
479
   STGetOptionsPrefix - Gets the prefix used for searching for all
480
   ST options in the database.
481
 
482
   Not Collective
483
 
484
   Input Parameters:
485
.  st - the spectral transformation context
486
 
487
   Output Parameters:
488
.  prefix - pointer to the prefix string used, is returned
489
 
490
   Notes: On the Fortran side, the user should pass in a string 'prefix' of
491
   sufficient length to hold the prefix.
492
 
493
   Level: advanced
494
 
495
.seealso: STSetOptionsPrefix(), STAppendOptionsPrefix()
496
@*/
812 dsic.upv.es!antodo 497
PetscErrorCode STGetOptionsPrefix(ST st,const char *prefix[])
6 dsic.upv.es!jroman 498
{
476 dsic.upv.es!antodo 499
  PetscErrorCode ierr;
6 dsic.upv.es!jroman 500
 
501
  PetscFunctionBegin;
2213 jroman 502
  PetscValidHeaderSpecific(st,ST_CLASSID,1);
2319 jroman 503
  PetscValidPointer(prefix,2);
6 dsic.upv.es!jroman 504
  ierr = PetscObjectGetOptionsPrefix((PetscObject)st, prefix);CHKERRQ(ierr);
505
  PetscFunctionReturn(0);
506
}
507
 
508
#undef __FUNCT__  
509
#define __FUNCT__ "STView"
510
/*@C
511
   STView - Prints the ST data structure.
512
 
513
   Collective on ST
514
 
515
   Input Parameters:
516
+  ST - the ST context
517
-  viewer - optional visualization context
518
 
519
   Note:
520
   The available visualization contexts include
521
+     PETSC_VIEWER_STDOUT_SELF - standard output (default)
522
-     PETSC_VIEWER_STDOUT_WORLD - synchronized standard
523
         output where only the first processor opens
524
         the file.  All other processors send their
525
         data to the first processor to print.
526
 
527
   The user can open an alternative visualization contexts with
528
   PetscViewerASCIIOpen() (output to a specified file).
529
 
530
   Level: beginner
531
 
532
.seealso: EPSView(), PetscViewerASCIIOpen()
533
@*/
476 dsic.upv.es!antodo 534
PetscErrorCode STView(ST st,PetscViewer viewer)
6 dsic.upv.es!jroman 535
{
476 dsic.upv.es!antodo 536
  PetscErrorCode    ierr;
1502 slepc 537
  const STType      cstr;
1004 slepc 538
  const char*       str;
2216 jroman 539
  PetscBool         isascii,isstring;
6 dsic.upv.es!jroman 540
  PetscViewerFormat format;
541
 
542
  PetscFunctionBegin;
2213 jroman 543
  PetscValidHeaderSpecific(st,ST_CLASSID,1);
1422 slepc 544
  if (!viewer) viewer = PETSC_VIEWER_STDOUT_(((PetscObject)st)->comm);
2213 jroman 545
  PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,2);
25 dsic.upv.es!jroman 546
  PetscCheckSameComm(st,1,viewer,2);
6 dsic.upv.es!jroman 547
 
2215 jroman 548
  ierr = PetscTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&isascii);CHKERRQ(ierr);
549
  ierr = PetscTypeCompare((PetscObject)viewer,PETSCVIEWERSTRING,&isstring);CHKERRQ(ierr);
6 dsic.upv.es!jroman 550
  if (isascii) {
551
    ierr = PetscViewerGetFormat(viewer,&format);CHKERRQ(ierr);
2224 jroman 552
    ierr = PetscObjectPrintClassNamePrefixType((PetscObject)st,viewer,"ST Object");CHKERRQ(ierr);
6 dsic.upv.es!jroman 553
#if !defined(PETSC_USE_COMPLEX)
358 dsic.upv.es!antodo 554
    ierr = PetscViewerASCIIPrintf(viewer,"  shift: %g\n",st->sigma);CHKERRQ(ierr);
6 dsic.upv.es!jroman 555
#else
358 dsic.upv.es!antodo 556
    ierr = PetscViewerASCIIPrintf(viewer,"  shift: %g+%g i\n",PetscRealPart(st->sigma),PetscImaginaryPart(st->sigma));CHKERRQ(ierr);
6 dsic.upv.es!jroman 557
#endif
344 dsic.upv.es!antodo 558
    switch (st->shift_matrix) {
1940 jroman 559
    case ST_MATMODE_COPY:
344 dsic.upv.es!antodo 560
      break;
1940 jroman 561
    case ST_MATMODE_INPLACE:
344 dsic.upv.es!antodo 562
      ierr = PetscViewerASCIIPrintf(viewer,"Shifting the matrix and unshifting at exit\n");CHKERRQ(ierr);
563
      break;
1940 jroman 564
    case ST_MATMODE_SHELL:
344 dsic.upv.es!antodo 565
      ierr = PetscViewerASCIIPrintf(viewer,"Using a shell matrix\n");CHKERRQ(ierr);
566
      break;
567
    }
1940 jroman 568
    if (st->B && st->shift_matrix != ST_MATMODE_SHELL) {
344 dsic.upv.es!antodo 569
      switch (st->str) {
570
        case SAME_NONZERO_PATTERN:      str = "same nonzero pattern";break;
571
        case DIFFERENT_NONZERO_PATTERN: str = "different nonzero pattern";break;
572
        case SUBSET_NONZERO_PATTERN:    str = "subset nonzero pattern";break;
2214 jroman 573
        default:                        SETERRQ(((PetscObject)st)->comm,1,"Wrong structure flag");
344 dsic.upv.es!antodo 574
      }
575
      ierr = PetscViewerASCIIPrintf(viewer,"Matrices A and B have %s\n",str);CHKERRQ(ierr);
576
    }
6 dsic.upv.es!jroman 577
    if (st->ops->view) {
578
      ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
579
      ierr = (*st->ops->view)(st,viewer);CHKERRQ(ierr);
580
      ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
581
    }
582
  } else if (isstring) {
583
    ierr = STGetType(st,&cstr);CHKERRQ(ierr);
584
    ierr = PetscViewerStringSPrintf(viewer," %-7.7s",cstr);CHKERRQ(ierr);
585
    if (st->ops->view) {ierr = (*st->ops->view)(st,viewer);CHKERRQ(ierr);}
586
  } else {
2214 jroman 587
    SETERRQ1(((PetscObject)st)->comm,1,"Viewer type %s not supported by ST",((PetscObject)viewer)->type_name);
6 dsic.upv.es!jroman 588
  }
589
  PetscFunctionReturn(0);
590
}
591
 
438 dsic.upv.es!antodo 592
#undef __FUNCT__  
593
#define __FUNCT__ "STView_Default"
476 dsic.upv.es!antodo 594
PetscErrorCode STView_Default(ST st,PetscViewer viewer)
438 dsic.upv.es!antodo 595
{
476 dsic.upv.es!antodo 596
  PetscErrorCode ierr;
2216 jroman 597
  PetscBool      isascii,isstring;
438 dsic.upv.es!antodo 598
 
599
  PetscFunctionBegin;
2215 jroman 600
  ierr = PetscTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&isascii);CHKERRQ(ierr);
601
  ierr = PetscTypeCompare((PetscObject)viewer,PETSCVIEWERSTRING,&isstring);CHKERRQ(ierr);
438 dsic.upv.es!antodo 602
  if (isascii) {
603
    ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
604
    ierr = PetscViewerASCIIPrintf(viewer,"Associated KSP object\n");CHKERRQ(ierr);
605
    ierr = PetscViewerASCIIPrintf(viewer,"------------------------------\n");CHKERRQ(ierr);
606
    ierr = KSPView(st->ksp,viewer);CHKERRQ(ierr);
607
    ierr = PetscViewerASCIIPrintf(viewer,"------------------------------\n");CHKERRQ(ierr);
608
    ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
609
  } else if (isstring) {
610
    ierr = KSPView(st->ksp,viewer);CHKERRQ(ierr);
611
  }
612
  PetscFunctionReturn(0);
613
}
614
 
6 dsic.upv.es!jroman 615
/*MC
616
   STRegisterDynamic - Adds a method to the spectral transformation package.
617
 
618
   Synopsis:
1508 slepc 619
   STRegisterDynamic(char *name_solver,char *path,char *name_create,PetscErrorCode (*routine_create)(ST))
6 dsic.upv.es!jroman 620
 
621
   Not collective
622
 
623
   Input Parameters:
624
+  name_solver - name of a new user-defined solver
625
.  path - path (either absolute or relative) the library containing this solver
626
.  name_create - name of routine to create method context
627
-  routine_create - routine to create method context
628
 
629
   Notes:
630
   STRegisterDynamic() may be called multiple times to add several user-defined spectral transformations.
631
 
632
   If dynamic libraries are used, then the fourth input argument (routine_create)
633
   is ignored.
634
 
635
   Sample usage:
636
.vb
637
   STRegisterDynamic("my_solver","/home/username/my_lib/lib/libO/solaris/mylib.a",
638
              "MySolverCreate",MySolverCreate);
639
.ve
640
 
641
   Then, your solver can be chosen with the procedural interface via
642
$     STSetType(st,"my_solver")
643
   or at runtime via the option
644
$     -st_type my_solver
645
 
646
   Level: advanced
647
 
1389 slepc 648
   $PETSC_DIR, $PETSC_ARCH and $PETSC_LIB_DIR occuring in pathname will be replaced with appropriate values.
6 dsic.upv.es!jroman 649
 
1389 slepc 650
.seealso: STRegisterDestroy(), STRegisterAll()
6 dsic.upv.es!jroman 651
M*/
652
 
653
#undef __FUNCT__  
654
#define __FUNCT__ "STRegister"
1389 slepc 655
/*@C
2317 jroman 656
   STRegister - See STRegisterDynamic()
1389 slepc 657
 
2317 jroman 658
   Level: advanced
1389 slepc 659
@*/
1508 slepc 660
PetscErrorCode STRegister(const char *sname,const char *path,const char *name,PetscErrorCode (*function)(ST))
6 dsic.upv.es!jroman 661
{
476 dsic.upv.es!antodo 662
  PetscErrorCode ierr;
663
  char           fullname[256];
6 dsic.upv.es!jroman 664
 
665
  PetscFunctionBegin;
666
  ierr = PetscFListConcat(path,name,fullname);CHKERRQ(ierr);
667
  ierr = PetscFListAdd(&STList,sname,fullname,(void (*)(void))function);CHKERRQ(ierr);
668
  PetscFunctionReturn(0);
669
}
1389 slepc 670
 
671
#undef __FUNCT__  
672
#define __FUNCT__ "STRegisterDestroy"
673
/*@
674
   STRegisterDestroy - Frees the list of ST methods that were
675
   registered by STRegisterDynamic().
676
 
677
   Not Collective
678
 
679
   Level: advanced
680
 
681
.seealso: STRegisterDynamic(), STRegisterAll()
682
@*/
683
PetscErrorCode STRegisterDestroy(void)
684
{
685
  PetscErrorCode ierr;
686
 
687
  PetscFunctionBegin;
688
  ierr = PetscFListDestroy(&STList);CHKERRQ(ierr);
689
  ierr = STRegisterAll(PETSC_NULL);CHKERRQ(ierr);
690
  PetscFunctionReturn(0);
691
}