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