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