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
2757 jroman 1
/*
2
   Basic PS routines
3
 
4
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
5
   SLEPc - Scalable Library for Eigenvalue Problem Computations
6
   Copyright (c) 2002-2011, Universitat Politecnica de Valencia, Spain
7
 
8
   This file is part of SLEPc.
9
 
10
   SLEPc is free software: you can redistribute it and/or modify it under  the
11
   terms of version 3 of the GNU Lesser General Public License as published by
12
   the Free Software Foundation.
13
 
14
   SLEPc  is  distributed in the hope that it will be useful, but WITHOUT  ANY
15
   WARRANTY;  without even the implied warranty of MERCHANTABILITY or  FITNESS
16
   FOR  A  PARTICULAR PURPOSE. See the GNU Lesser General Public  License  for
17
   more details.
18
 
19
   You  should have received a copy of the GNU Lesser General  Public  License
20
   along with SLEPc. If not, see <http://www.gnu.org/licenses/>.
21
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
22
*/
23
 
24
#include <slepc-private/psimpl.h>      /*I "slepcps.h" I*/
25
 
26
PetscFList       PSList = 0;
27
PetscBool        PSRegisterAllCalled = PETSC_FALSE;
28
PetscClassId     PS_CLASSID = 0;
2766 jroman 29
PetscLogEvent    PS_Solve = 0,PS_Sort = 0,PS_Cond = 0;
2757 jroman 30
static PetscBool PSPackageInitialized = PETSC_FALSE;
31
 
32
#undef __FUNCT__  
33
#define __FUNCT__ "PSFinalizePackage"
34
/*@C
35
   PSFinalizePackage - This function destroys everything in the Slepc interface
36
   to the PS package. It is called from SlepcFinalize().
37
 
38
   Level: developer
39
 
40
.seealso: SlepcFinalize()
41
@*/
42
PetscErrorCode PSFinalizePackage(void)
43
{
44
  PetscFunctionBegin;
45
  PSPackageInitialized = PETSC_FALSE;
46
  PSList               = 0;
47
  PSRegisterAllCalled  = PETSC_FALSE;
48
  PetscFunctionReturn(0);
49
}
50
 
51
#undef __FUNCT__  
52
#define __FUNCT__ "PSInitializePackage"
53
/*@C
54
  PSInitializePackage - This function initializes everything in the PS package.
55
  It is called from PetscDLLibraryRegister() when using dynamic libraries, and
56
  on the first call to PSCreate() when using static libraries.
57
 
58
  Input Parameter:
59
  path - The dynamic library path, or PETSC_NULL
60
 
61
  Level: developer
62
 
63
.seealso: SlepcInitialize()
64
@*/
65
PetscErrorCode PSInitializePackage(const char *path)
66
{
67
  char             logList[256];
68
  char             *className;
69
  PetscBool        opt;
70
  PetscErrorCode   ierr;
71
 
72
  PetscFunctionBegin;
73
  if (PSPackageInitialized) PetscFunctionReturn(0);
74
  PSPackageInitialized = PETSC_TRUE;
75
  /* Register Classes */
76
  ierr = PetscClassIdRegister("Projected system",&PS_CLASSID);CHKERRQ(ierr);
77
  /* Register Constructors */
78
  ierr = PSRegisterAll(path);CHKERRQ(ierr);
79
  /* Register Events */
80
  ierr = PetscLogEventRegister("PSSolve",PS_CLASSID,&PS_Solve);CHKERRQ(ierr);
81
  ierr = PetscLogEventRegister("PSSort",PS_CLASSID,&PS_Sort);CHKERRQ(ierr);
2766 jroman 82
  ierr = PetscLogEventRegister("PSCond",PS_CLASSID,&PS_Cond);CHKERRQ(ierr);
2757 jroman 83
  /* Process info exclusions */
84
  ierr = PetscOptionsGetString(PETSC_NULL,"-info_exclude",logList,256,&opt);CHKERRQ(ierr);
85
  if (opt) {
86
    ierr = PetscStrstr(logList,"ps",&className);CHKERRQ(ierr);
87
    if (className) {
88
      ierr = PetscInfoDeactivateClass(PS_CLASSID);CHKERRQ(ierr);
89
    }
90
  }
91
  /* Process summary exclusions */
92
  ierr = PetscOptionsGetString(PETSC_NULL,"-log_summary_exclude",logList,256,&opt);CHKERRQ(ierr);
93
  if (opt) {
94
    ierr = PetscStrstr(logList,"ps",&className);CHKERRQ(ierr);
95
    if (className) {
96
      ierr = PetscLogEventDeactivateClass(PS_CLASSID);CHKERRQ(ierr);
97
    }
98
  }
99
  ierr = PetscRegisterFinalize(PSFinalizePackage);CHKERRQ(ierr);
100
  PetscFunctionReturn(0);
101
}
102
 
103
#undef __FUNCT__  
104
#define __FUNCT__ "PSCreate"
105
/*@C
106
   PSCreate - Creates a PS context.
107
 
108
   Collective on MPI_Comm
109
 
110
   Input Parameter:
111
.  comm - MPI communicator
112
 
113
   Output Parameter:
114
.  newps - location to put the PS context
115
 
116
   Level: beginner
117
 
118
   Note:
119
   PS objects are not intended for normal users but only for
120
   advanced user that for instance implement their own solvers.
121
 
122
.seealso: PSDestroy(), PS
123
@*/
124
PetscErrorCode PSCreate(MPI_Comm comm,PS *newps)
125
{
126
  PS             ps;
127
  PetscInt       i;
128
  PetscErrorCode ierr;
129
 
130
  PetscFunctionBegin;
131
  PetscValidPointer(newps,2);
132
  ierr = PetscHeaderCreate(ps,_p_PS,struct _PSOps,PS_CLASSID,-1,"PS","Projected System","PS",comm,PSDestroy,PSView);CHKERRQ(ierr);
2758 jroman 133
  *newps    = ps;
134
  ps->state = PS_STATE_RAW;
135
  ps->ld    = 0;
136
  ps->l     = 0;
137
  ps->n     = 0;
138
  ps->k     = 0;
2757 jroman 139
  for (i=0;i<PS_NUM_MAT;i++) {
2758 jroman 140
    ps->mat[i]  = PETSC_NULL;
2757 jroman 141
    ps->rmat[i] = PETSC_NULL;
142
  }
2758 jroman 143
  ps->work  = PETSC_NULL;
2757 jroman 144
  ps->rwork = PETSC_NULL;
2766 jroman 145
  ps->iwork = PETSC_NULL;
2757 jroman 146
  PetscFunctionReturn(0);
147
}
148
 
149
#undef __FUNCT__  
150
#define __FUNCT__ "PSSetOptionsPrefix"
151
/*@C
152
   PSSetOptionsPrefix - Sets the prefix used for searching for all
153
   PS options in the database.
154
 
155
   Logically Collective on PS
156
 
157
   Input Parameters:
158
+  ps - the projected system context
159
-  prefix - the prefix string to prepend to all PS option requests
160
 
161
   Notes:
162
   A hyphen (-) must NOT be given at the beginning of the prefix name.
163
   The first character of all runtime options is AUTOMATICALLY the
164
   hyphen.
165
 
166
   Level: advanced
167
 
168
.seealso: PSAppendOptionsPrefix()
169
@*/
170
PetscErrorCode PSSetOptionsPrefix(PS ps,const char *prefix)
171
{
172
  PetscErrorCode ierr;
173
 
174
  PetscFunctionBegin;
175
  PetscValidHeaderSpecific(ps,PS_CLASSID,1);
176
  ierr = PetscObjectSetOptionsPrefix((PetscObject)ps,prefix);CHKERRQ(ierr);
177
  PetscFunctionReturn(0);
178
}
179
 
180
#undef __FUNCT__  
181
#define __FUNCT__ "PSAppendOptionsPrefix"
182
/*@C
183
   PSAppendOptionsPrefix - Appends to the prefix used for searching for all
184
   PS options in the database.
185
 
186
   Logically Collective on PS
187
 
188
   Input Parameters:
189
+  ps - the projected system context
190
-  prefix - the prefix string to prepend to all PS option requests
191
 
192
   Notes:
193
   A hyphen (-) must NOT be given at the beginning of the prefix name.
194
   The first character of all runtime options is AUTOMATICALLY the hyphen.
195
 
196
   Level: advanced
197
 
198
.seealso: PSSetOptionsPrefix()
199
@*/
200
PetscErrorCode PSAppendOptionsPrefix(PS ps,const char *prefix)
201
{
202
  PetscErrorCode ierr;
203
 
204
  PetscFunctionBegin;
205
  PetscValidHeaderSpecific(ps,PS_CLASSID,1);
206
  ierr = PetscObjectAppendOptionsPrefix((PetscObject)ps,prefix);CHKERRQ(ierr);
207
  PetscFunctionReturn(0);
208
}
209
 
210
#undef __FUNCT__
211
#define __FUNCT__ "PSGetOptionsPrefix"
212
/*@C
213
   PSGetOptionsPrefix - Gets the prefix used for searching for all
214
   PS options in the database.
215
 
216
   Not Collective
217
 
218
   Input Parameters:
219
.  ps - the projected system context
220
 
221
   Output Parameters:
222
.  prefix - pointer to the prefix string used is returned
223
 
224
   Notes: On the fortran side, the user should pass in a string 'prefix' of
225
   sufficient length to hold the prefix.
226
 
227
   Level: advanced
228
 
229
.seealso: PSSetOptionsPrefix(), PSAppendOptionsPrefix()
230
@*/
231
PetscErrorCode PSGetOptionsPrefix(PS ps,const char *prefix[])
232
{
233
  PetscErrorCode ierr;
234
 
235
  PetscFunctionBegin;
236
  PetscValidHeaderSpecific(ps,PS_CLASSID,1);
237
  PetscValidPointer(prefix,2);
238
  ierr = PetscObjectGetOptionsPrefix((PetscObject)ps,prefix);CHKERRQ(ierr);
239
  PetscFunctionReturn(0);
240
}
241
 
242
#undef __FUNCT__  
243
#define __FUNCT__ "PSSetType"
244
/*@C
245
   PSSetType - Selects the type for the PS object.
246
 
247
   Logically Collective on PS
248
 
249
   Input Parameter:
250
+  ps   - the projected system context.
251
-  type - a known type
252
 
253
   Level: advanced
254
 
255
.seealso: PSGetType()
256
 
257
@*/
258
PetscErrorCode PSSetType(PS ps,const PSType type)
259
{
260
  PetscErrorCode ierr,(*r)(PS);
261
  PetscBool      match;
262
 
263
  PetscFunctionBegin;
264
  PetscValidHeaderSpecific(ps,PS_CLASSID,1);
265
  PetscValidCharPointer(type,2);
266
 
267
  ierr = PetscTypeCompare((PetscObject)ps,type,&match);CHKERRQ(ierr);
268
  if (match) PetscFunctionReturn(0);
269
 
270
  ierr =  PetscFListFind(PSList,((PetscObject)ps)->comm,type,PETSC_TRUE,(void (**)(void))&r);CHKERRQ(ierr);
271
  if (!r) SETERRQ1(((PetscObject)ps)->comm,PETSC_ERR_ARG_UNKNOWN_TYPE,"Unable to find requested PS type %s",type);
272
 
273
  ierr = PetscMemzero(ps->ops,sizeof(struct _PSOps));CHKERRQ(ierr);
274
 
275
  ierr = PetscObjectChangeTypeName((PetscObject)ps,type);CHKERRQ(ierr);
276
  ierr = (*r)(ps);CHKERRQ(ierr);
277
  PetscFunctionReturn(0);
278
}
279
 
280
#undef __FUNCT__  
281
#define __FUNCT__ "PSGetType"
282
/*@C
283
   PSGetType - Gets the PS type name (as a string) from the PS context.
284
 
285
   Not Collective
286
 
287
   Input Parameter:
288
.  ps - the projected system context
289
 
290
   Output Parameter:
291
.  name - name of the projected system
292
 
293
   Level: advanced
294
 
295
.seealso: PSSetType()
296
 
297
@*/
298
PetscErrorCode PSGetType(PS ps,const PSType *type)
299
{
300
  PetscFunctionBegin;
301
  PetscValidHeaderSpecific(ps,PS_CLASSID,1);
302
  PetscValidPointer(type,2);
303
  *type = ((PetscObject)ps)->type_name;
304
  PetscFunctionReturn(0);
305
}
306
 
307
#undef __FUNCT__  
308
#define __FUNCT__ "PSSetFromOptions"
309
/*@
310
   PSSetFromOptions - Sets PS options from the options database.
311
 
312
   Collective on PS
313
 
314
   Input Parameters:
315
.  ps - the projected system context
316
 
317
   Notes:  
318
   To see all options, run your program with the -help option.
319
 
320
   Level: beginner
321
@*/
322
PetscErrorCode PSSetFromOptions(PS ps)
323
{
324
  PetscErrorCode ierr;
325
 
326
  PetscFunctionBegin;
327
  PetscValidHeaderSpecific(ps,PS_CLASSID,1);
328
  if (!PSRegisterAllCalled) { ierr = PSRegisterAll(PETSC_NULL);CHKERRQ(ierr); }
329
  /* Set default type (we do not allow changing it with -ps_type) */
330
  if (!((PetscObject)ps)->type_name) {
2758 jroman 331
    ierr = PSSetType(ps,PSNHEP);CHKERRQ(ierr);
2757 jroman 332
  }
333
  ierr = PetscOptionsBegin(((PetscObject)ps)->comm,((PetscObject)ps)->prefix,"Projecte System (PS) Options","PS");CHKERRQ(ierr);
334
    ierr = PetscObjectProcessOptionsHandlers((PetscObject)ps);CHKERRQ(ierr);
335
  ierr = PetscOptionsEnd();CHKERRQ(ierr);
336
  PetscFunctionReturn(0);
337
}
338
 
339
#undef __FUNCT__  
340
#define __FUNCT__ "PSView"
341
/*@C
342
   PSView - Prints the PS data structure.
343
 
344
   Collective on PS
345
 
346
   Input Parameters:
347
+  ps - the projected system context
348
-  viewer - optional visualization context
349
 
350
   Note:
351
   The available visualization contexts include
352
+     PETSC_VIEWER_STDOUT_SELF - standard output (default)
353
-     PETSC_VIEWER_STDOUT_WORLD - synchronized standard
354
         output where only the first processor opens
355
         the file.  All other processors send their
356
         data to the first processor to print.
357
 
358
   The user can open an alternative visualization context with
359
   PetscViewerASCIIOpen() - output to a specified file.
360
 
361
   Level: beginner
362
 
363
.seealso: PetscViewerASCIIOpen()
364
@*/
365
PetscErrorCode PSView(PS ps,PetscViewer viewer)
366
{
367
  PetscBool      isascii;
2758 jroman 368
  const char     *state;
2757 jroman 369
  PetscErrorCode ierr;
370
 
371
  PetscFunctionBegin;
372
  PetscValidHeaderSpecific(ps,PS_CLASSID,1);
373
  if (!viewer) viewer = PETSC_VIEWER_STDOUT_(((PetscObject)ps)->comm);
374
  PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,2);
375
  PetscCheckSameComm(ps,1,viewer,2);
376
  ierr = PetscTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&isascii);CHKERRQ(ierr);
377
  if (isascii) {
378
    ierr = PetscObjectPrintClassNamePrefixType((PetscObject)ps,viewer,"PS Object");CHKERRQ(ierr);
2758 jroman 379
     switch (ps->state) {
380
       case PS_STATE_RAW:          state = "raw"; break;
381
       case PS_STATE_INTERMEDIATE: state = "intermediate"; break;
382
       case PS_STATE_CONDENSED:    state = "condensed"; break;
383
       case PS_STATE_SORTED:       state = "sorted"; break;
384
       default: SETERRQ(((PetscObject)ps)->comm,1,"Wrong value of ps->state");
385
     }
386
    ierr = PetscViewerASCIIPrintf(viewer,"  current state: %s\n",state);CHKERRQ(ierr);
387
    ierr = PetscViewerASCIIPrintf(viewer,"  dimensions: ld=%d, n=%d, l=%d, k=%d\n",ps->ld,ps->n,ps->l,ps->k);CHKERRQ(ierr);
2762 jroman 388
  } else SETERRQ1(((PetscObject)ps)->comm,1,"Viewer type %s not supported for PS",((PetscObject)viewer)->type_name);
2757 jroman 389
  PetscFunctionReturn(0);
390
}
391
 
392
#undef __FUNCT__  
2758 jroman 393
#define __FUNCT__ "PSAllocate"
394
/*@
395
   PSAllocate - Allocates memory for internal storage or matrices in PS.
396
 
397
   Collective on PS
398
 
399
   Input Parameters:
400
+  ps - the projected system context
401
-  ld - leading dimension (maximum allowed dimension for the matrices)
402
 
403
   Level: advanced
404
 
405
.seealso: PSGetLeadingDimension(), PSSetDimensions()
406
@*/
407
PetscErrorCode PSAllocate(PS ps,PetscInt ld)
408
{
409
  PetscErrorCode ierr;
410
 
411
  PetscFunctionBegin;
412
  PetscValidHeaderSpecific(ps,PS_CLASSID,1);
413
  PetscValidLogicalCollectiveInt(ps,ld,2);
414
  if (ld<1) SETERRQ(((PetscObject)ps)->comm,PETSC_ERR_ARG_OUTOFRANGE,"Leading dimension should be at least one");
415
  ierr = PSReset(ps);CHKERRQ(ierr);
416
  ps->ld = ld;
417
  ps->n  = ld;
418
  ierr = (*ps->ops->allocate)(ps,ld);CHKERRQ(ierr);
419
  PetscFunctionReturn(0);
420
}
421
 
422
#undef __FUNCT__  
423
#define __FUNCT__ "PSAllocateMat_Private"
424
PetscErrorCode PSAllocateMat_Private(PS ps,PSMatType m)
425
{
2764 jroman 426
  PetscInt       sz;
2758 jroman 427
  PetscErrorCode ierr;
428
 
429
  PetscFunctionBegin;
430
  sz = ps->ld*ps->ld*sizeof(PetscScalar);
2765 jroman 431
  ierr = PetscFree(ps->mat[m]);CHKERRQ(ierr);
2758 jroman 432
  ierr = PetscMalloc(sz,&ps->mat[m]);CHKERRQ(ierr);
433
  ierr = PetscMemzero(ps->mat[m],sz);CHKERRQ(ierr);
434
  ierr = PetscLogObjectMemory(ps,sz);CHKERRQ(ierr);
435
  PetscFunctionReturn(0);
436
}
437
 
438
#undef __FUNCT__  
439
#define __FUNCT__ "PSGetLeadingDimension"
440
/*@
441
   PSGetLeadingDimension - Returns the leading dimension of the allocated
442
   matrices.
443
 
444
   Not Collective
445
 
446
   Input Parameter:
447
.  ps - the projected system context
448
 
449
   Output Parameter:
450
.  ld - leading dimension (maximum allowed dimension for the matrices)
451
 
452
   Level: advanced
453
 
454
.seealso: PSAllocate(), PSSetDimensions()
455
@*/
456
PetscErrorCode PSGetLeadingDimension(PS ps,PetscInt *ld)
457
{
458
  PetscFunctionBegin;
459
  PetscValidHeaderSpecific(ps,PS_CLASSID,1);
460
  if (ld) *ld = ps->ld;
461
  PetscFunctionReturn(0);
462
}
463
 
464
#undef __FUNCT__  
465
#define __FUNCT__ "PSSetState"
466
/*@
467
   PSSetState - Change the state of the PS object.
468
 
469
   Collective on PS
470
 
471
   Input Parameters:
472
+  ps    - the projected system context
473
-  state - the new state
474
 
475
   Notes:
476
   The state indicates that the projected system is in an initial state (raw),
477
   in an intermediate state (such as tridiagonal, Hessenberg or
478
   Hessenberg-triangular), in a condensed state (such as diagonal, Schur or
479
   generalized Schur), or in a sorted condensed state (according to a given
480
   sorting criterion).
481
 
482
   This function is normally used to return to the raw state when the
483
   condensed structure is destroyed.
484
 
485
   Level: advanced
486
 
487
.seealso: PSGetState()
488
@*/
489
PetscErrorCode PSSetState(PS ps,PSStateType state)
490
{
491
  PetscErrorCode ierr;
492
 
493
  PetscFunctionBegin;
494
  PetscValidHeaderSpecific(ps,PS_CLASSID,1);
495
  PetscValidLogicalCollectiveEnum(ps,state,2);
496
  switch (state) {
497
    case PS_STATE_RAW:
498
    case PS_STATE_INTERMEDIATE:
499
    case PS_STATE_CONDENSED:
500
    case PS_STATE_SORTED:
501
      if (ps->state<state) { ierr = PetscInfo(ps,"PS state has been increased\n");CHKERRQ(ierr); }
502
      ps->state = state;
2763 jroman 503
      break;
2758 jroman 504
    default:
505
      SETERRQ(((PetscObject)ps)->comm,PETSC_ERR_ARG_WRONG,"Wrong state");
506
  }
507
  PetscFunctionReturn(0);
508
}
509
 
510
#undef __FUNCT__  
511
#define __FUNCT__ "PSGetState"
512
/*@
513
   PSGetState - Returns the current state.
514
 
515
   Not Collective
516
 
517
   Input Parameter:
518
.  ps - the projected system context
519
 
520
   Output Parameter:
521
.  state - current state
522
 
523
   Level: advanced
524
 
525
.seealso: PSSetState()
526
@*/
527
PetscErrorCode PSGetState(PS ps,PSStateType *state)
528
{
529
  PetscFunctionBegin;
530
  PetscValidHeaderSpecific(ps,PS_CLASSID,1);
531
  if (state) *state = ps->state;
532
  PetscFunctionReturn(0);
533
}
534
 
535
#undef __FUNCT__  
536
#define __FUNCT__ "PSSetDimensions"
537
/*@
538
   PSSetDimensions - Resize the matrices in the PS object.
539
 
540
   Collective on PS
541
 
542
   Input Parameters:
543
+  ps - the projected system context
544
.  n  - the new size
545
.  l  - number of locked (inactive) leading columns
546
-  k  - intermediate dimension (e.g., position of arrow)
547
 
548
   Note:
549
   The internal arrays are not reallocated.
550
 
551
   Level: advanced
552
 
553
.seealso: PSGetDimensions(), PSAllocate()
554
@*/
555
PetscErrorCode PSSetDimensions(PS ps,PetscInt n,PetscInt l,PetscInt k)
556
{
557
  PetscFunctionBegin;
558
  PetscValidHeaderSpecific(ps,PS_CLASSID,1);
559
  PetscValidLogicalCollectiveInt(ps,n,2);
560
  PetscValidLogicalCollectiveInt(ps,l,3);
561
  PetscValidLogicalCollectiveInt(ps,k,4);
562
  if (!ps->ld) SETERRQ(((PetscObject)ps)->comm,PETSC_ERR_ORDER,"Must call PSAllocate() first");
563
  if (n!=PETSC_IGNORE) {
564
    if (n==PETSC_DECIDE || n==PETSC_DEFAULT) {
565
      ps->n = ps->ld;
566
    } else {
567
      if (n<1 || n>ps->ld) SETERRQ(((PetscObject)ps)->comm,PETSC_ERR_ARG_OUTOFRANGE,"Illegal value of n. Must be between 1 and ld");
568
      ps->n = n;
569
    }
570
  }
571
  if (l!=PETSC_IGNORE) {
572
    if (l==PETSC_DECIDE || l==PETSC_DEFAULT) {
573
      ps->l = 0;
574
    } else {
575
      if (l<0 || l>ps->n) SETERRQ(((PetscObject)ps)->comm,PETSC_ERR_ARG_OUTOFRANGE,"Illegal value of l. Must be between 0 and n");
576
      ps->l = l;
577
    }
578
  }
579
  if (k!=PETSC_IGNORE) {
580
    if (k==PETSC_DECIDE || k==PETSC_DEFAULT) {
581
      ps->k = ps->n/2;
582
    } else {
583
      if (k<0 || k>ps->n) SETERRQ(((PetscObject)ps)->comm,PETSC_ERR_ARG_OUTOFRANGE,"Illegal value of k. Must be between 0 and n");
584
      ps->k = k;
585
    }
586
  }
587
  PetscFunctionReturn(0);
588
}
589
 
590
#undef __FUNCT__  
591
#define __FUNCT__ "PSGetDimensions"
592
/*@
593
   PSGetDimensions - Returns the current dimensions.
594
 
595
   Not Collective
596
 
597
   Input Parameter:
598
.  ps - the projected system context
599
 
600
   Output Parameter:
601
.  state - current dimensions
602
 
603
   Level: advanced
604
 
605
.seealso: PSSetDimensions()
606
@*/
607
PetscErrorCode PSGetDimensions(PS ps,PetscInt *n,PetscInt *l,PetscInt *k)
608
{
609
  PetscFunctionBegin;
610
  PetscValidHeaderSpecific(ps,PS_CLASSID,1);
611
  if (n) *n = ps->n;
612
  if (l) *l = ps->l;
613
  if (k) *k = ps->k;
614
  PetscFunctionReturn(0);
615
}
616
 
617
#undef __FUNCT__  
2759 jroman 618
#define __FUNCT__ "PSGetArray"
619
/*@C
620
   PSGetArray - Returns a pointer to one of the internal arrays used to
621
   represent matrices. You MUST call PSRestoreArray() when you no longer
622
   need to access the array.
623
 
624
   Not Collective
625
 
626
   Input Parameters:
627
+  ps - the projected system context
628
-  m - the requested matrix
629
 
630
   Output Parameter:
631
.  a - pointer to the values
632
 
633
   Level: advanced
634
 
635
.seealso: PSRestoreArray(), PSGetArrayReal()
636
@*/
637
PetscErrorCode PSGetArray(PS ps,PSMatType m,PetscScalar *a[])
638
{
639
  PetscFunctionBegin;
640
  PetscValidHeaderSpecific(ps,PS_CLASSID,1);
641
  PetscValidPointer(a,2);
642
  if (m<0 || m>=PS_NUM_MAT) SETERRQ(((PetscObject)ps)->comm,PETSC_ERR_ARG_WRONG,"Invalid matrix");
643
  if (!ps->ld) SETERRQ(((PetscObject)ps)->comm,PETSC_ERR_ORDER,"Must call PSAllocate() first");
644
  if (!ps->mat[m]) SETERRQ(((PetscObject)ps)->comm,PETSC_ERR_ARG_WRONGSTATE,"Requested matrix was not created in this PS");
645
  *a = ps->mat[m];
646
  CHKMEMQ;
647
  PetscFunctionReturn(0);
648
}
649
 
650
#undef __FUNCT__  
651
#define __FUNCT__ "PSRestoreArray"
652
/*@C
653
   PSRestoreArray - Restores the matrix after PSGetArray() was called.
654
 
655
   Not Collective
656
 
657
   Input Parameters:
658
+  ps - the projected system context
659
.  m - the requested matrix
660
-  a - pointer to the values
661
 
662
   Level: advanced
663
 
664
.seealso: PSGetArray(), PSGetArrayReal()
665
@*/
666
PetscErrorCode PSRestoreArray(PS ps,PSMatType m,PetscScalar *a[])
667
{
668
  PetscErrorCode ierr;
669
 
670
  PetscFunctionBegin;
671
  PetscValidHeaderSpecific(ps,PS_CLASSID,1);
672
  PetscValidPointer(a,2);
673
  if (m<0 || m>=PS_NUM_MAT) SETERRQ(((PetscObject)ps)->comm,PETSC_ERR_ARG_WRONG,"Invalid matrix");
674
  CHKMEMQ;
675
  *a = 0;
676
  ierr = PetscObjectStateIncrease((PetscObject)ps);CHKERRQ(ierr);
677
  PetscFunctionReturn(0);
678
}
679
 
680
#undef __FUNCT__  
681
#define __FUNCT__ "PSSolve"
682
/*@
683
   PSSolve - Solves the problem.
684
 
685
   Not Collective
686
 
687
   Input Parameters:
688
+  ps   - the projected system context
689
.  eigr - array to store the computed eigenvalues (real part)
690
-  eigi - array to store the computed eigenvalues (imaginary part)
691
 
692
   Note:
693
   This call brings the projected system to condensed form. No ordering
694
   is enforced, call PSSort() later if you want the solution sorted.
695
 
696
   Level: advanced
697
 
698
.seealso: PSSort()
699
@*/
700
PetscErrorCode PSSolve(PS ps,PetscScalar *eigr,PetscScalar *eigi)
701
{
702
  PetscErrorCode ierr;
703
 
704
  PetscFunctionBegin;
705
  PetscValidHeaderSpecific(ps,PS_CLASSID,1);
706
  if (!ps->ld) SETERRQ(((PetscObject)ps)->comm,PETSC_ERR_ORDER,"Must call PSAllocate() first");
707
  if (!ps->ops->solve) SETERRQ1(((PetscObject)ps)->comm,PETSC_ERR_SUP,"PS type %s",((PetscObject)ps)->type_name);
708
  ierr = PetscLogEventBegin(PS_Solve,ps,0,0,0);CHKERRQ(ierr);
709
  ierr = PetscFPTrapPush(PETSC_FP_TRAP_OFF);CHKERRQ(ierr);
710
  ierr = (*ps->ops->solve)(ps,eigr,eigi);CHKERRQ(ierr);
711
  ierr = PetscFPTrapPop();CHKERRQ(ierr);
712
  ierr = PetscLogEventEnd(PS_Solve,ps,0,0,0);CHKERRQ(ierr);
713
  ps->state = PS_STATE_CONDENSED;
714
  ierr = PetscObjectStateIncrease((PetscObject)ps);CHKERRQ(ierr);
715
  PetscFunctionReturn(0);
716
}
717
 
718
#undef __FUNCT__  
2766 jroman 719
#define __FUNCT__ "PSCond"
720
/*@C
721
   PSCond - Compute the inf-norm condition number of the first matrix
722
   as cond(A) = norm(A)*norm(inv(A)).
723
 
724
   Not Collective
725
 
726
   Input Parameters:
727
+  ps - the projected system context
728
-  cond - the computed condition number
729
 
730
   Level: advanced
731
 
732
.seealso: PSSolve()
733
@*/
734
PetscErrorCode PSCond(PS ps,PetscReal *cond)
735
{
736
  PetscErrorCode ierr;
737
 
738
  PetscFunctionBegin;
739
  PetscValidHeaderSpecific(ps,PS_CLASSID,1);
740
  if (!ps->ops->cond) SETERRQ1(((PetscObject)ps)->comm,PETSC_ERR_SUP,"PS type %s",((PetscObject)ps)->type_name);
741
  ierr = PetscLogEventBegin(PS_Cond,ps,0,0,0);CHKERRQ(ierr);
742
  ierr = PetscFPTrapPush(PETSC_FP_TRAP_OFF);CHKERRQ(ierr);
743
  ierr = (*ps->ops->cond)(ps,cond);CHKERRQ(ierr);
744
  ierr = PetscFPTrapPop();CHKERRQ(ierr);
745
  ierr = PetscLogEventEnd(PS_Cond,ps,0,0,0);CHKERRQ(ierr);
746
  ps->state = PS_STATE_SORTED;
747
  ierr = PetscObjectStateIncrease((PetscObject)ps);CHKERRQ(ierr);
748
  PetscFunctionReturn(0);
749
}
750
 
751
#undef __FUNCT__  
2759 jroman 752
#define __FUNCT__ "PSSort"
2763 jroman 753
/*@C
2759 jroman 754
   PSSort - Reorders the condensed form computed by PSSolve() according to
755
   a given sorting criterion.
756
 
757
   Not Collective
758
 
759
   Input Parameters:
760
+  ps - the projected system context
761
.  eigr - array to store the sorted eigenvalues (real part)
762
-  eigi - array to store the sorted eigenvalues (imaginary part)
763
 
764
   Level: advanced
765
 
766
.seealso: PSSolve()
767
@*/
2763 jroman 768
PetscErrorCode PSSort(PS ps,PetscScalar *eigr,PetscScalar *eigi,PetscErrorCode (*comp_func)(PetscScalar,PetscScalar,PetscScalar,PetscScalar,PetscInt*,void*),void *comp_ctx)
2759 jroman 769
{
770
  PetscErrorCode ierr;
771
 
772
  PetscFunctionBegin;
773
  PetscValidHeaderSpecific(ps,PS_CLASSID,1);
774
  if (ps->state!=PS_STATE_CONDENSED) SETERRQ(((PetscObject)ps)->comm,PETSC_ERR_ORDER,"Must call PSSolve() first");
775
  if (!ps->ops->sort) SETERRQ1(((PetscObject)ps)->comm,PETSC_ERR_SUP,"PS type %s",((PetscObject)ps)->type_name);
776
  ierr = PetscLogEventBegin(PS_Sort,ps,0,0,0);CHKERRQ(ierr);
777
  ierr = PetscFPTrapPush(PETSC_FP_TRAP_OFF);CHKERRQ(ierr);
2763 jroman 778
  ierr = (*ps->ops->sort)(ps,eigr,eigi,comp_func,comp_ctx);CHKERRQ(ierr);
2759 jroman 779
  ierr = PetscFPTrapPop();CHKERRQ(ierr);
780
  ierr = PetscLogEventEnd(PS_Sort,ps,0,0,0);CHKERRQ(ierr);
781
  ps->state = PS_STATE_SORTED;
782
  ierr = PetscObjectStateIncrease((PetscObject)ps);CHKERRQ(ierr);
783
  PetscFunctionReturn(0);
784
}
785
 
786
#undef __FUNCT__  
2757 jroman 787
#define __FUNCT__ "PSReset"
2758 jroman 788
/*@
2757 jroman 789
   PSReset - Resets the PS context to the initial state.
790
 
791
   Collective on PS
792
 
793
   Input Parameter:
794
.  ps - the projected system context
795
 
796
   Level: advanced
797
 
798
.seealso: PSDestroy()
799
@*/
800
PetscErrorCode PSReset(PS ps)
801
{
802
  PetscInt       i;
803
  PetscErrorCode ierr;
804
 
805
  PetscFunctionBegin;
806
  PetscValidHeaderSpecific(ps,PS_CLASSID,1);
2758 jroman 807
  ps->state = PS_STATE_RAW;
808
  ps->ld    = 0;
809
  ps->l     = 0;
810
  ps->n     = 0;
811
  ps->k     = 0;
2757 jroman 812
  for (i=0;i<PS_NUM_MAT;i++) {
813
    ierr = PetscFree(ps->mat[i]);CHKERRQ(ierr);
814
    ierr = PetscFree(ps->rmat[i]);CHKERRQ(ierr);
815
  }
816
  ierr = PetscFree(ps->work);CHKERRQ(ierr);
817
  ierr = PetscFree(ps->rwork);CHKERRQ(ierr);
2766 jroman 818
  ierr = PetscFree(ps->iwork);CHKERRQ(ierr);
2757 jroman 819
  PetscFunctionReturn(0);
820
}
821
 
822
#undef __FUNCT__  
823
#define __FUNCT__ "PSDestroy"
824
/*@C
825
   PSDestroy - Destroys PS context that was created with PSCreate().
826
 
827
   Collective on PS
828
 
829
   Input Parameter:
830
.  ps - the projected system context
831
 
832
   Level: beginner
833
 
834
.seealso: PSCreate()
835
@*/
836
PetscErrorCode PSDestroy(PS *ps)
837
{
838
  PetscErrorCode ierr;
839
 
840
  PetscFunctionBegin;
841
  if (!*ps) PetscFunctionReturn(0);
842
  PetscValidHeaderSpecific(*ps,PS_CLASSID,1);
843
  if (--((PetscObject)(*ps))->refct > 0) { *ps = 0; PetscFunctionReturn(0); }
844
  ierr = PSReset(*ps);CHKERRQ(ierr);
845
  ierr = PetscHeaderDestroy(ps);CHKERRQ(ierr);
846
  PetscFunctionReturn(0);
847
}
848
 
849
#undef __FUNCT__  
850
#define __FUNCT__ "PSRegister"
851
/*@C
852
   PSRegister - See PSRegisterDynamic()
853
 
854
   Level: advanced
855
@*/
856
PetscErrorCode PSRegister(const char *sname,const char *path,const char *name,PetscErrorCode (*function)(PS))
857
{
858
  PetscErrorCode ierr;
859
  char           fullname[PETSC_MAX_PATH_LEN];
860
 
861
  PetscFunctionBegin;
862
  ierr = PetscFListConcat(path,name,fullname);CHKERRQ(ierr);
863
  ierr = PetscFListAdd(&PSList,sname,fullname,(void (*)(void))function);CHKERRQ(ierr);
864
  PetscFunctionReturn(0);
865
}
866
 
867
#undef __FUNCT__  
868
#define __FUNCT__ "PSRegisterDestroy"
869
/*@
870
   PSRegisterDestroy - Frees the list of PS methods that were
871
   registered by PSRegisterDynamic().
872
 
873
   Not Collective
874
 
875
   Level: advanced
876
 
877
.seealso: PSRegisterDynamic(), PSRegisterAll()
878
@*/
879
PetscErrorCode PSRegisterDestroy(void)
880
{
881
  PetscErrorCode ierr;
882
 
883
  PetscFunctionBegin;
884
  ierr = PetscFListDestroy(&PSList);CHKERRQ(ierr);
885
  PSRegisterAllCalled = PETSC_FALSE;
886
  PetscFunctionReturn(0);
887
}
888
 
889
EXTERN_C_BEGIN
2758 jroman 890
extern PetscErrorCode PSCreate_NHEP(PS);
2757 jroman 891
EXTERN_C_END
892
 
893
#undef __FUNCT__  
894
#define __FUNCT__ "PSRegisterAll"
895
/*@C
896
   PSRegisterAll - Registers all of the projected systems in the PS package.
897
 
898
   Not Collective
899
 
900
   Input Parameter:
901
.  path - the library where the routines are to be found (optional)
902
 
903
   Level: advanced
904
@*/
905
PetscErrorCode PSRegisterAll(const char *path)
906
{
907
  PetscErrorCode ierr;
908
 
909
  PetscFunctionBegin;
910
  PSRegisterAllCalled = PETSC_TRUE;
2758 jroman 911
  ierr = PSRegisterDynamic(PSNHEP,path,"PSCreate_NHEP",PSCreate_NHEP);CHKERRQ(ierr);
2757 jroman 912
  PetscFunctionReturn(0);
913
}
914