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
519 dsic.upv.es!antodo 1
/*
2
     The basic EPS routines, Create, View, etc. are here.
1376 slepc 3
 
4
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1672 slepc 5
   SLEPc - Scalable Library for Eigenvalue Problem Computations
6
   Copyright (c) 2002-2009, 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
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
519 dsic.upv.es!antodo 22
*/
1376 slepc 23
 
1521 slepc 24
#include "private/epsimpl.h"      /*I "slepceps.h" I*/
519 dsic.upv.es!antodo 25
 
26
PetscFList EPSList = 0;
842 dsic.upv.es!antodo 27
PetscCookie EPS_COOKIE = 0;
1493 slepc 28
PetscLogEvent EPS_SetUp = 0, EPS_Solve = 0, EPS_Dense = 0;
1851 antodo 29
static PetscTruth EPSPackageInitialized = PETSC_FALSE;
519 dsic.upv.es!antodo 30
 
31
#undef __FUNCT__  
1851 antodo 32
#define __FUNCT__ "EPSFinalizePackage"
33
/*@C
1853 antodo 34
  EPSFinalizePackage - This function destroys everything in the Slepc interface to the EPS package. It is
35
  called from SlepcFinalize().
1851 antodo 36
 
37
  Level: developer
38
 
1853 antodo 39
.seealso: SlepcFinalize()
1851 antodo 40
@*/
41
PetscErrorCode EPSFinalizePackage(void)
42
{
43
  PetscFunctionBegin;
44
  EPSPackageInitialized = PETSC_FALSE;
45
  EPSList               = 0;
46
  PetscFunctionReturn(0);
47
}
48
 
49
#undef __FUNCT__  
842 dsic.upv.es!antodo 50
#define __FUNCT__ "EPSInitializePackage"
51
/*@C
52
  EPSInitializePackage - This function initializes everything in the EPS package. It is called
53
  from PetscDLLibraryRegister() when using dynamic libraries, and on the first call to EPSCreate()
54
  when using static libraries.
55
 
56
  Input Parameter:
57
  path - The dynamic library path, or PETSC_NULL
58
 
59
  Level: developer
60
 
61
.seealso: SlepcInitialize()
62
@*/
63
PetscErrorCode EPSInitializePackage(char *path) {
64
  char              logList[256];
65
  char             *className;
66
  PetscTruth        opt;
67
  PetscErrorCode ierr;
68
 
69
  PetscFunctionBegin;
1851 antodo 70
  if (EPSPackageInitialized) PetscFunctionReturn(0);
71
  EPSPackageInitialized = PETSC_TRUE;
842 dsic.upv.es!antodo 72
  /* Register Classes */
1493 slepc 73
  ierr = PetscCookieRegister("Eigenproblem Solver",&EPS_COOKIE);CHKERRQ(ierr);
842 dsic.upv.es!antodo 74
  /* Register Constructors */
75
  ierr = EPSRegisterAll(path);CHKERRQ(ierr);
76
  /* Register Events */
1493 slepc 77
  ierr = PetscLogEventRegister("EPSSetUp",EPS_COOKIE,&EPS_SetUp);CHKERRQ(ierr);
78
  ierr = PetscLogEventRegister("EPSSolve",EPS_COOKIE,&EPS_Solve);CHKERRQ(ierr);
79
  ierr = PetscLogEventRegister("EPSDense",EPS_COOKIE,&EPS_Dense); CHKERRQ(ierr);
842 dsic.upv.es!antodo 80
  /* Process info exclusions */
81
  ierr = PetscOptionsGetString(PETSC_NULL, "-log_info_exclude", logList, 256, &opt);CHKERRQ(ierr);
82
  if (opt) {
83
    ierr = PetscStrstr(logList, "eps", &className);CHKERRQ(ierr);
84
    if (className) {
1037 slepc 85
      ierr = PetscInfoDeactivateClass(EPS_COOKIE);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, "eps", &className);CHKERRQ(ierr);
92
    if (className) {
93
      ierr = PetscLogEventDeactivateClass(EPS_COOKIE);CHKERRQ(ierr);
94
    }
95
  }
1851 antodo 96
  ierr = PetscRegisterFinalize(EPSFinalizePackage);CHKERRQ(ierr);
842 dsic.upv.es!antodo 97
  PetscFunctionReturn(0);
98
}
99
 
100
#undef __FUNCT__  
519 dsic.upv.es!antodo 101
#define __FUNCT__ "EPSView"
102
/*@C
103
   EPSView - Prints the EPS data structure.
104
 
105
   Collective on EPS
106
 
107
   Input Parameters:
108
+  eps - the eigenproblem solver context
109
-  viewer - optional visualization context
110
 
111
   Options Database Key:
112
.  -eps_view -  Calls EPSView() at end of EPSSolve()
113
 
114
   Note:
115
   The available visualization contexts include
116
+     PETSC_VIEWER_STDOUT_SELF - standard output (default)
117
-     PETSC_VIEWER_STDOUT_WORLD - synchronized standard
118
         output where only the first processor opens
119
         the file.  All other processors send their
120
         data to the first processor to print.
121
 
122
   The user can open an alternative visualization context with
123
   PetscViewerASCIIOpen() - output to a specified file.
124
 
125
   Level: beginner
126
 
127
.seealso: STView(), PetscViewerASCIIOpen()
128
@*/
129
PetscErrorCode EPSView(EPS eps,PetscViewer viewer)
130
{
131
  PetscErrorCode ierr;
1818 jroman 132
  const char     *type,*extr,*bal;
1004 slepc 133
  PetscTruth     isascii;
519 dsic.upv.es!antodo 134
 
135
  PetscFunctionBegin;
136
  PetscValidHeaderSpecific(eps,EPS_COOKIE,1);
1422 slepc 137
  if (!viewer) viewer = PETSC_VIEWER_STDOUT_(((PetscObject)eps)->comm);
519 dsic.upv.es!antodo 138
  PetscValidHeaderSpecific(viewer,PETSC_VIEWER_COOKIE,2);
139
  PetscCheckSameComm(eps,1,viewer,2);
140
 
141
#if defined(PETSC_USE_COMPLEX)
142
#define HERM "hermitian"
143
#else
144
#define HERM "symmetric"
145
#endif
146
  ierr = PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&isascii);CHKERRQ(ierr);
147
  if (isascii) {
148
    ierr = PetscViewerASCIIPrintf(viewer,"EPS Object:\n");CHKERRQ(ierr);
149
    switch (eps->problem_type) {
150
      case EPS_HEP:   type = HERM " eigenvalue problem"; break;
151
      case EPS_GHEP:  type = "generalized " HERM " eigenvalue problem"; break;
152
      case EPS_NHEP:  type = "non-" HERM " eigenvalue problem"; break;
153
      case EPS_GNHEP: type = "generalized non-" HERM " eigenvalue problem"; break;
1656 slepc 154
      case EPS_PGNHEP: type = "generalized non-" HERM " eigenvalue problem with " HERM " positive definite B"; break;
1915 jroman 155
      case EPS_GHIEP: type = "generalized " HERM "-indefinite eigenvalue problem"; break;
519 dsic.upv.es!antodo 156
      case 0:         type = "not yet set"; break;
157
      default: SETERRQ(1,"Wrong value of eps->problem_type");
158
    }
159
    ierr = PetscViewerASCIIPrintf(viewer,"  problem type: %s\n",type);CHKERRQ(ierr);
160
    ierr = EPSGetType(eps,&type);CHKERRQ(ierr);
161
    if (type) {
1947 jroman 162
      ierr = PetscViewerASCIIPrintf(viewer,"  method: %s\n",type);CHKERRQ(ierr);
519 dsic.upv.es!antodo 163
    } else {
164
      ierr = PetscViewerASCIIPrintf(viewer,"  method: not yet set\n");CHKERRQ(ierr);
165
    }
166
    if (eps->ops->view) {
167
      ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
168
      ierr = (*eps->ops->view)(eps,viewer);CHKERRQ(ierr);
169
      ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
170
    }
1560 slepc 171
    if (eps->extraction) {
172
      switch (eps->extraction) {
173
        case EPS_RITZ:             extr = "Rayleigh-Ritz"; break;
174
        case EPS_HARMONIC:         extr = "harmonic Ritz"; break;
175
        case EPS_REFINED:          extr = "refined Ritz"; break;
176
        case EPS_REFINED_HARMONIC: extr = "refined harmonic Ritz"; break;
177
        default: SETERRQ(1,"Wrong value of eps->extraction");
1426 slepc 178
      }
1560 slepc 179
      ierr = PetscViewerASCIIPrintf(viewer,"  extraction type: %s\n",extr);CHKERRQ(ierr);
1426 slepc 180
    }
1940 jroman 181
    if (eps->balance && !eps->ishermitian && eps->balance!=EPS_BALANCE_NONE) {
1799 jroman 182
      switch (eps->balance) {
1940 jroman 183
        case EPS_BALANCE_ONESIDE:   bal = "one-sided Krylov"; break;
184
        case EPS_BALANCE_TWOSIDE:   bal = "two-sided Krylov"; break;
185
        case EPS_BALANCE_USER:      bal = "user-defined matrix"; break;
1799 jroman 186
        default: SETERRQ(1,"Wrong value of eps->balance");
187
      }
1804 jroman 188
      ierr = PetscViewerASCIIPrintf(viewer,"  balancing enabled: %s",bal);CHKERRQ(ierr);
1940 jroman 189
      if (eps->balance==EPS_BALANCE_ONESIDE || eps->balance==EPS_BALANCE_TWOSIDE) {
1804 jroman 190
        ierr = PetscViewerASCIIPrintf(viewer,", with its=%d",eps->balance_its);CHKERRQ(ierr);
191
      }
1940 jroman 192
      if (eps->balance==EPS_BALANCE_TWOSIDE && eps->balance_cutoff!=0.0) {
1799 jroman 193
        ierr = PetscViewerASCIIPrintf(viewer," and cutoff=%g",eps->balance_cutoff);CHKERRQ(ierr);
194
      }
195
      ierr = PetscViewerASCIIPrintf(viewer,"\n");CHKERRQ(ierr);
196
    }
1425 slepc 197
    ierr = PetscViewerASCIIPrintf(viewer,"  selected portion of the spectrum: ");CHKERRQ(ierr);
1942 jroman 198
    if (!eps->which) {
199
      ierr = PetscViewerASCIIPrintf(viewer,"not yet set\n");CHKERRQ(ierr);
200
    } else switch (eps->which) {
1945 jroman 201
      case EPS_WHICH_USER:
1782 antodo 202
        ierr = PetscViewerASCIIPrintf(viewer,"user defined\n");CHKERRQ(ierr);
203
        break;
204
      case EPS_TARGET_MAGNITUDE:
1818 jroman 205
#if !defined(PETSC_USE_COMPLEX)
206
        ierr = PetscViewerASCIIPrintf(viewer,"closest to target: %g (in magnitude)\n",eps->target);CHKERRQ(ierr);
207
#else
208
        ierr = PetscViewerASCIIPrintf(viewer,"closest to target: %g+%g i (in magnitude)\n",PetscRealPart(eps->target),PetscImaginaryPart(eps->target));CHKERRQ(ierr);
209
#endif
210
        break;
1782 antodo 211
      case EPS_TARGET_REAL:
1425 slepc 212
#if !defined(PETSC_USE_COMPLEX)
1818 jroman 213
        ierr = PetscViewerASCIIPrintf(viewer,"closest to target: %g (along the real axis)\n",eps->target);CHKERRQ(ierr);
1425 slepc 214
#else
1818 jroman 215
        ierr = PetscViewerASCIIPrintf(viewer,"closest to target: %g+%g i (along the real axis)\n",PetscRealPart(eps->target),PetscImaginaryPart(eps->target));CHKERRQ(ierr);
1425 slepc 216
#endif
1782 antodo 217
        break;
1818 jroman 218
#if defined(PETSC_USE_COMPLEX)
219
      case EPS_TARGET_IMAGINARY:
220
        ierr = PetscViewerASCIIPrintf(viewer,"closest to target: %g+%g i (along the imaginary axis)\n",PetscRealPart(eps->target),PetscImaginaryPart(eps->target));CHKERRQ(ierr);
221
        break;
222
#endif
223
      case EPS_LARGEST_MAGNITUDE:
224
        ierr = PetscViewerASCIIPrintf(viewer,"largest eigenvalues in magnitude\n");CHKERRQ(ierr);
225
        break;
226
      case EPS_SMALLEST_MAGNITUDE:
227
        ierr = PetscViewerASCIIPrintf(viewer,"smallest eigenvalues in magnitude\n");CHKERRQ(ierr);
228
        break;
229
      case EPS_LARGEST_REAL:
230
        ierr = PetscViewerASCIIPrintf(viewer,"largest real parts\n");CHKERRQ(ierr);
231
        break;
232
      case EPS_SMALLEST_REAL:
233
        ierr = PetscViewerASCIIPrintf(viewer,"smallest real parts\n");CHKERRQ(ierr);
234
        break;
235
      case EPS_LARGEST_IMAGINARY:
236
        ierr = PetscViewerASCIIPrintf(viewer,"largest imaginary parts\n");CHKERRQ(ierr);
237
        break;
238
      case EPS_SMALLEST_IMAGINARY:
239
        ierr = PetscViewerASCIIPrintf(viewer,"smallest imaginary parts\n");CHKERRQ(ierr);
240
        break;
1782 antodo 241
      default: SETERRQ(1,"Wrong value of eps->which");
242
    }    
1944 jroman 243
    if (eps->leftvecs) {
244
      ierr = PetscViewerASCIIPrintf(viewer,"  computing left eigenvectors also\n");CHKERRQ(ierr);
245
    }
2031 jroman 246
    if (eps->trueres) {
247
      ierr = PetscViewerASCIIPrintf(viewer,"  computing true residuals explicitly\n");CHKERRQ(ierr);
248
    }
519 dsic.upv.es!antodo 249
    ierr = PetscViewerASCIIPrintf(viewer,"  number of eigenvalues (nev): %d\n",eps->nev);CHKERRQ(ierr);
600 dsic.upv.es!jroman 250
    ierr = PetscViewerASCIIPrintf(viewer,"  number of column vectors (ncv): %d\n",eps->ncv);CHKERRQ(ierr);
1575 slepc 251
    ierr = PetscViewerASCIIPrintf(viewer,"  maximum dimension of projected problem (mpd): %d\n",eps->mpd);CHKERRQ(ierr);
519 dsic.upv.es!antodo 252
    ierr = PetscViewerASCIIPrintf(viewer,"  maximum number of iterations: %d\n", eps->max_it);
253
    ierr = PetscViewerASCIIPrintf(viewer,"  tolerance: %g\n",eps->tol);CHKERRQ(ierr);
1938 jroman 254
    if (eps->nini!=0) {
255
      ierr = PetscViewerASCIIPrintf(viewer,"  dimension of user-provided initial space: %d\n",PetscAbs(eps->nini));CHKERRQ(ierr);
256
    }
257
    if (eps->ninil!=0) {
258
      ierr = PetscViewerASCIIPrintf(viewer,"  dimension of user-provided initial left space: %d\n",PetscAbs(eps->ninil));CHKERRQ(ierr);
259
    }
260
    if (eps->nds>0) {
261
      ierr = PetscViewerASCIIPrintf(viewer,"  dimension of user-provided deflation space: %d\n",eps->nds);CHKERRQ(ierr);
262
    }
1957 jroman 263
    ierr = PetscViewerASCIIPrintf(viewer,"  estimates of matrix norms (%s): norm(A)=%g",eps->adaptive?"adaptive":"constant",eps->nrma);CHKERRQ(ierr);
264
    if (eps->isgeneralized) {
265
      ierr = PetscViewerASCIIPrintf(viewer,", norm(B)=%g",eps->nrmb);CHKERRQ(ierr);
266
    }
267
    ierr = PetscViewerASCIIPrintf(viewer,"\n");CHKERRQ(ierr);
519 dsic.upv.es!antodo 268
    ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
1345 slepc 269
    ierr = IPView(eps->ip,viewer); CHKERRQ(ierr);
519 dsic.upv.es!antodo 270
    ierr = STView(eps->OP,viewer); CHKERRQ(ierr);
271
    ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
272
  } else {
273
    if (eps->ops->view) {
274
      ierr = (*eps->ops->view)(eps,viewer);CHKERRQ(ierr);
275
    }
276
    ierr = STView(eps->OP,viewer); CHKERRQ(ierr);
277
  }
278
  PetscFunctionReturn(0);
279
}
280
 
281
#undef __FUNCT__  
282
#define __FUNCT__ "EPSCreate"
283
/*@C
284
   EPSCreate - Creates the default EPS context.
285
 
286
   Collective on MPI_Comm
287
 
288
   Input Parameter:
289
.  comm - MPI communicator
290
 
291
   Output Parameter:
292
.  eps - location to put the EPS context
293
 
294
   Note:
1198 slepc 295
   The default EPS type is EPSKRYLOVSCHUR
519 dsic.upv.es!antodo 296
 
297
   Level: beginner
298
 
299
.seealso: EPSSetUp(), EPSSolve(), EPSDestroy(), EPS
300
@*/
301
PetscErrorCode EPSCreate(MPI_Comm comm,EPS *outeps)
302
{
303
  PetscErrorCode ierr;
304
  EPS            eps;
305
 
306
  PetscFunctionBegin;
307
  PetscValidPointer(outeps,2);
308
  *outeps = 0;
309
 
1454 slepc 310
  ierr = PetscHeaderCreate(eps,_p_EPS,struct _EPSOps,EPS_COOKIE,-1,"EPS",comm,EPSDestroy,EPSView);CHKERRQ(ierr);
519 dsic.upv.es!antodo 311
  *outeps = eps;
312
 
313
  ierr = PetscMemzero(eps->ops,sizeof(struct _EPSOps));CHKERRQ(ierr);
314
 
315
  eps->max_it          = 0;
316
  eps->nev             = 1;
317
  eps->ncv             = 0;
1575 slepc 318
  eps->mpd             = 0;
519 dsic.upv.es!antodo 319
  eps->allocated_ncv   = 0;
1932 jroman 320
  eps->nini            = 0;
1937 jroman 321
  eps->ninil           = 0;
519 dsic.upv.es!antodo 322
  eps->nds             = 0;
1282 slepc 323
  eps->tol             = 1e-7;
1785 antodo 324
  eps->conv            = PETSC_NULL;
325
  eps->conv_func       = EPSDefaultConverged;
326
  eps->conv_ctx        = PETSC_NULL;
1942 jroman 327
  eps->which           = (EPSWhich)0;
1782 antodo 328
  eps->which_func      = PETSC_NULL;
329
  eps->which_ctx       = PETSC_NULL;
1944 jroman 330
  eps->leftvecs        = PETSC_FALSE;
2031 jroman 331
  eps->trueres         = PETSC_FALSE;
1425 slepc 332
  eps->target          = 0.0;
519 dsic.upv.es!antodo 333
  eps->evecsavailable  = PETSC_FALSE;
334
  eps->problem_type    = (EPSProblemType)0;
1560 slepc 335
  eps->extraction      = (EPSExtraction)0;
1799 jroman 336
  eps->balance         = (EPSBalance)0;
337
  eps->balance_its     = 5;
338
  eps->balance_cutoff  = 1e-8;
1957 jroman 339
  eps->nrma            = 1.0;
340
  eps->nrmb            = 1.0;
341
  eps->adaptive        = PETSC_FALSE;
519 dsic.upv.es!antodo 342
 
343
  eps->V               = 0;
780 dsic.upv.es!jroman 344
  eps->W               = 0;
519 dsic.upv.es!antodo 345
  eps->T               = 0;
1794 antodo 346
  eps->Z               = 0;
519 dsic.upv.es!antodo 347
  eps->DS              = 0;
1937 jroman 348
  eps->IS              = 0;
349
  eps->ISL             = 0;
1917 jroman 350
  eps->ds_ortho        = PETSC_FALSE;
519 dsic.upv.es!antodo 351
  eps->eigr            = 0;
352
  eps->eigi            = 0;
353
  eps->errest          = 0;
780 dsic.upv.es!jroman 354
  eps->errest_left     = 0;
519 dsic.upv.es!antodo 355
  eps->OP              = 0;
1345 slepc 356
  eps->ip              = 0;
519 dsic.upv.es!antodo 357
  eps->data            = 0;
358
  eps->nconv           = 0;
359
  eps->its             = 0;
360
  eps->perm            = PETSC_NULL;
1830 antodo 361
  eps->ldz             = 0;
519 dsic.upv.es!antodo 362
 
363
  eps->nwork           = 0;
364
  eps->work            = 0;
365
  eps->isgeneralized   = PETSC_FALSE;
366
  eps->ishermitian     = PETSC_FALSE;
1358 slepc 367
  eps->ispositive      = PETSC_FALSE;
519 dsic.upv.es!antodo 368
  eps->setupcalled     = 0;
369
  eps->reason          = EPS_CONVERGED_ITERATING;
370
 
371
  eps->numbermonitors  = 0;
372
 
373
  ierr = STCreate(comm,&eps->OP); CHKERRQ(ierr);
374
  PetscLogObjectParent(eps,eps->OP);
1345 slepc 375
  ierr = IPCreate(comm,&eps->ip); CHKERRQ(ierr);
1422 slepc 376
  ierr = IPSetOptionsPrefix(eps->ip,((PetscObject)eps)->prefix);
1345 slepc 377
  ierr = IPAppendOptionsPrefix(eps->ip,"eps_");
378
  PetscLogObjectParent(eps,eps->ip);
519 dsic.upv.es!antodo 379
  ierr = PetscPublishAll(eps);CHKERRQ(ierr);
380
  PetscFunctionReturn(0);
381
}
382
 
383
#undef __FUNCT__  
384
#define __FUNCT__ "EPSSetType"
385
/*@C
386
   EPSSetType - Selects the particular solver to be used in the EPS object.
387
 
388
   Collective on EPS
389
 
390
   Input Parameters:
391
+  eps      - the eigensolver context
392
-  type     - a known method
393
 
394
   Options Database Key:
395
.  -eps_type <method> - Sets the method; use -help for a list
396
    of available methods
397
 
398
   Notes:  
545 dsic.upv.es!jroman 399
   See "slepc/include/slepceps.h" for available methods. The default
1198 slepc 400
   is EPSKRYLOVSCHUR.
519 dsic.upv.es!antodo 401
 
402
   Normally, it is best to use the EPSSetFromOptions() command and
403
   then set the EPS type from the options database rather than by using
404
   this routine.  Using the options database provides the user with
405
   maximum flexibility in evaluating the different available methods.
406
   The EPSSetType() routine is provided for those situations where it
407
   is necessary to set the iterative solver independently of the command
408
   line or options database.
409
 
410
   Level: intermediate
411
 
412
.seealso: STSetType(), EPSType
413
@*/
1502 slepc 414
PetscErrorCode EPSSetType(EPS eps,const EPSType type)
519 dsic.upv.es!antodo 415
{
416
  PetscErrorCode ierr,(*r)(EPS);
417
  PetscTruth match;
418
 
419
  PetscFunctionBegin;
420
  PetscValidHeaderSpecific(eps,EPS_COOKIE,1);
421
  PetscValidCharPointer(type,2);
422
 
423
  ierr = PetscTypeCompare((PetscObject)eps,type,&match);CHKERRQ(ierr);
424
  if (match) PetscFunctionReturn(0);
425
 
426
  if (eps->data) {
427
    /* destroy the old private EPS context */
428
    ierr = (*eps->ops->destroy)(eps); CHKERRQ(ierr);
429
    eps->data = 0;
430
  }
431
 
1422 slepc 432
  ierr = PetscFListFind(EPSList,((PetscObject)eps)->comm,type,(void (**)(void)) &r);CHKERRQ(ierr);
519 dsic.upv.es!antodo 433
 
434
  if (!r) SETERRQ1(1,"Unknown EPS type given: %s",type);
435
 
436
  eps->setupcalled = 0;
437
  ierr = PetscMemzero(eps->ops,sizeof(struct _EPSOps));CHKERRQ(ierr);
438
  ierr = (*r)(eps); CHKERRQ(ierr);
439
 
440
  ierr = PetscObjectChangeTypeName((PetscObject)eps,type);CHKERRQ(ierr);
441
  PetscFunctionReturn(0);
442
}
443
 
444
#undef __FUNCT__  
445
#define __FUNCT__ "EPSGetType"
446
/*@C
447
   EPSGetType - Gets the EPS type as a string from the EPS object.
448
 
449
   Not Collective
450
 
451
   Input Parameter:
452
.  eps - the eigensolver context
453
 
454
   Output Parameter:
455
.  name - name of EPS method
456
 
457
   Level: intermediate
458
 
459
.seealso: EPSSetType()
460
@*/
1501 slepc 461
PetscErrorCode EPSGetType(EPS eps,const EPSType *type)
519 dsic.upv.es!antodo 462
{
463
  PetscFunctionBegin;
464
  PetscValidHeaderSpecific(eps,EPS_COOKIE,1);
1501 slepc 465
  PetscValidPointer(type,2);
1422 slepc 466
  *type = ((PetscObject)eps)->type_name;
519 dsic.upv.es!antodo 467
  PetscFunctionReturn(0);
468
}
469
 
470
/*MC
471
   EPSRegisterDynamic - Adds a method to the eigenproblem solver package.
472
 
473
   Synopsis:
1509 slepc 474
   EPSRegisterDynamic(char *name_solver,char *path,char *name_create,PetscErrorCode (*routine_create)(EPS))
519 dsic.upv.es!antodo 475
 
476
   Not Collective
477
 
478
   Input Parameters:
479
+  name_solver - name of a new user-defined solver
480
.  path - path (either absolute or relative) the library containing this solver
481
.  name_create - name of routine to create the solver context
482
-  routine_create - routine to create the solver context
483
 
484
   Notes:
485
   EPSRegisterDynamic() may be called multiple times to add several user-defined solvers.
486
 
487
   If dynamic libraries are used, then the fourth input argument (routine_create)
488
   is ignored.
489
 
490
   Sample usage:
491
.vb
492
   EPSRegisterDynamic("my_solver",/home/username/my_lib/lib/libO/solaris/mylib.a,
493
               "MySolverCreate",MySolverCreate);
494
.ve
495
 
496
   Then, your solver can be chosen with the procedural interface via
497
$     EPSSetType(eps,"my_solver")
498
   or at runtime via the option
499
$     -eps_type my_solver
500
 
501
   Level: advanced
502
 
1389 slepc 503
   Environmental variables such as ${PETSC_ARCH}, ${PETSC_DIR}, ${PETSC_LIB_DIR},
519 dsic.upv.es!antodo 504
   and others of the form ${any_environmental_variable} occuring in pathname will be
505
   replaced with appropriate values.
506
 
1389 slepc 507
.seealso: EPSRegisterDestroy(), EPSRegisterAll()
519 dsic.upv.es!antodo 508
 
509
M*/
510
 
511
#undef __FUNCT__  
512
#define __FUNCT__ "EPSRegister"
1389 slepc 513
/*@C
514
  EPSRegister - See EPSRegisterDynamic()
515
 
516
  Level: advanced
517
@*/
1509 slepc 518
PetscErrorCode EPSRegister(const char *sname,const char *path,const char *name,PetscErrorCode (*function)(EPS))
519 dsic.upv.es!antodo 519
{
520
  PetscErrorCode ierr;
521
  char           fullname[256];
522
 
523
  PetscFunctionBegin;
524
  ierr = PetscFListConcat(path,name,fullname);CHKERRQ(ierr);
525
  ierr = PetscFListAdd(&EPSList,sname,fullname,(void (*)(void))function);CHKERRQ(ierr);
526
  PetscFunctionReturn(0);
527
}
528
 
529
#undef __FUNCT__  
1389 slepc 530
#define __FUNCT__ "EPSRegisterDestroy"
531
/*@
532
   EPSRegisterDestroy - Frees the list of EPS methods that were
533
   registered by EPSRegisterDynamic().
534
 
535
   Not Collective
536
 
537
   Level: advanced
538
 
539
.seealso: EPSRegisterDynamic(), EPSRegisterAll()
540
@*/
541
PetscErrorCode EPSRegisterDestroy(void)
542
{
543
  PetscErrorCode ierr;
544
 
545
  PetscFunctionBegin;
546
  ierr = PetscFListDestroy(&EPSList);CHKERRQ(ierr);
547
  ierr = EPSRegisterAll(PETSC_NULL);CHKERRQ(ierr);
548
  PetscFunctionReturn(0);
549
}
550
 
551
#undef __FUNCT__  
519 dsic.upv.es!antodo 552
#define __FUNCT__ "EPSDestroy"
553
/*@
554
   EPSDestroy - Destroys the EPS context.
555
 
556
   Collective on EPS
557
 
558
   Input Parameter:
559
.  eps - eigensolver context obtained from EPSCreate()
560
 
561
   Level: beginner
562
 
563
.seealso: EPSCreate(), EPSSetUp(), EPSSolve()
564
@*/
565
PetscErrorCode EPSDestroy(EPS eps)
566
{
567
  PetscErrorCode ierr;
568
 
569
  PetscFunctionBegin;
570
  PetscValidHeaderSpecific(eps,EPS_COOKIE,1);
1422 slepc 571
  if (--((PetscObject)eps)->refct > 0) PetscFunctionReturn(0);
519 dsic.upv.es!antodo 572
 
573
  /* if memory was published with AMS then destroy it */
574
  ierr = PetscObjectDepublish(eps);CHKERRQ(ierr);
575
 
576
  ierr = STDestroy(eps->OP);CHKERRQ(ierr);
1345 slepc 577
  ierr = IPDestroy(eps->ip);CHKERRQ(ierr);
519 dsic.upv.es!antodo 578
 
579
  if (eps->ops->destroy) {
580
    ierr = (*eps->ops->destroy)(eps); CHKERRQ(ierr);
581
  }
582
 
1040 slepc 583
  ierr = PetscFree(eps->T);CHKERRQ(ierr);
584
  ierr = PetscFree(eps->Tl);CHKERRQ(ierr);
1794 antodo 585
  ierr = PetscFree(eps->Z);CHKERRQ(ierr);
1040 slepc 586
  ierr = PetscFree(eps->perm);CHKERRQ(ierr);
2027 jroman 587
  ierr = PetscRandomDestroy(eps->rand);CHKERRQ(ierr);
519 dsic.upv.es!antodo 588
 
1800 jroman 589
  if (eps->D) {
590
    ierr = VecDestroy(eps->D);CHKERRQ(ierr);
591
  }
592
 
1917 jroman 593
  ierr = EPSRemoveDeflationSpace(eps);CHKERRQ(ierr);
1331 slepc 594
  ierr = EPSMonitorCancel(eps);CHKERRQ(ierr);
1287 slepc 595
 
1570 slepc 596
  ierr = PetscHeaderDestroy(eps);CHKERRQ(ierr);
519 dsic.upv.es!antodo 597
  PetscFunctionReturn(0);
598
}
599
 
600
#undef __FUNCT__  
1425 slepc 601
#define __FUNCT__ "EPSSetTarget"
602
/*@
603
   EPSSetTarget - Sets the value of the target.
604
 
1811 jroman 605
   Collective on EPS
1425 slepc 606
 
607
   Input Parameters:
608
+  eps    - eigensolver context
609
-  target - the value of the target
610
 
611
   Notes:
612
   The target is a scalar value used to determine the portion of the spectrum
1811 jroman 613
   of interest. It is used in combination with EPSSetWhichEigenpairs().
1425 slepc 614
 
615
   Level: beginner
616
 
617
.seealso: EPSGetTarget(), EPSSetWhichEigenpairs()
618
@*/
619
PetscErrorCode EPSSetTarget(EPS eps,PetscScalar target)
620
{
621
  PetscFunctionBegin;
622
  PetscValidHeaderSpecific(eps,EPS_COOKIE,1);
623
  eps->target = target;
624
  PetscFunctionReturn(0);
625
}
626
 
627
#undef __FUNCT__  
628
#define __FUNCT__ "EPSGetTarget"
629
/*@
630
   EPSGetTarget - Gets the value of the target.
631
 
632
   Not collective
633
 
634
   Input Parameter:
635
.  eps - eigensolver context
636
 
637
   Output Parameter:
638
.  target - the value of the target
639
 
640
   Level: beginner
641
 
642
   Note:
643
   If the target was not set by the user, then zero is returned.
644
 
645
.seealso: EPSSetTarget()
646
@*/
647
PetscErrorCode EPSGetTarget(EPS eps,PetscScalar* target)
648
{
649
  PetscFunctionBegin;
650
  PetscValidHeaderSpecific(eps,EPS_COOKIE,1);
651
  if (target) {
1782 antodo 652
    *target = eps->target;
1425 slepc 653
  }
654
  PetscFunctionReturn(0);
655
}
656
 
657
#undef __FUNCT__  
519 dsic.upv.es!antodo 658
#define __FUNCT__ "EPSSetST"
659
/*@
660
   EPSSetST - Associates a spectral transformation object to the
661
   eigensolver.
662
 
1811 jroman 663
   Collective on EPS and ST
519 dsic.upv.es!antodo 664
 
665
   Input Parameters:
666
+  eps - eigensolver context obtained from EPSCreate()
667
-  st   - the spectral transformation object
668
 
669
   Note:
670
   Use EPSGetST() to retrieve the spectral transformation context (for example,
671
   to free it at the end of the computations).
672
 
673
   Level: advanced
674
 
675
.seealso: EPSGetST()
676
@*/
677
PetscErrorCode EPSSetST(EPS eps,ST st)
678
{
679
  PetscErrorCode ierr;
680
 
681
  PetscFunctionBegin;
682
  PetscValidHeaderSpecific(eps,EPS_COOKIE,1);
683
  PetscValidHeaderSpecific(st,ST_COOKIE,2);
684
  PetscCheckSameComm(eps,1,st,2);
1345 slepc 685
  ierr = PetscObjectReference((PetscObject)st);CHKERRQ(ierr);
519 dsic.upv.es!antodo 686
  ierr = STDestroy(eps->OP); CHKERRQ(ierr);
687
  eps->OP = st;
688
  PetscFunctionReturn(0);
689
}
690
 
691
#undef __FUNCT__  
692
#define __FUNCT__ "EPSGetST"
707 dsic.upv.es!antodo 693
/*@C
519 dsic.upv.es!antodo 694
   EPSGetST - Obtain the spectral transformation (ST) object associated
695
   to the eigensolver object.
696
 
697
   Not Collective
698
 
699
   Input Parameters:
700
.  eps - eigensolver context obtained from EPSCreate()
701
 
702
   Output Parameter:
703
.  st - spectral transformation context
704
 
705
   Level: beginner
706
 
707
.seealso: EPSSetST()
708
@*/
709
PetscErrorCode EPSGetST(EPS eps, ST *st)
710
{
711
  PetscFunctionBegin;
712
  PetscValidHeaderSpecific(eps,EPS_COOKIE,1);
1248 slepc 713
  PetscValidPointer(st,2);
519 dsic.upv.es!antodo 714
  *st = eps->OP;
715
  PetscFunctionReturn(0);
716
}
717
 
718
#undef __FUNCT__  
1345 slepc 719
#define __FUNCT__ "EPSSetIP"
720
/*@
1811 jroman 721
   EPSSetIP - Associates an inner product object to the eigensolver.
1345 slepc 722
 
1811 jroman 723
   Collective on EPS and IP
1345 slepc 724
 
725
   Input Parameters:
726
+  eps - eigensolver context obtained from EPSCreate()
727
-  ip  - the inner product object
728
 
729
   Note:
730
   Use EPSGetIP() to retrieve the inner product context (for example,
731
   to free it at the end of the computations).
732
 
733
   Level: advanced
734
 
735
.seealso: EPSGetIP()
736
@*/
737
PetscErrorCode EPSSetIP(EPS eps,IP ip)
738
{
739
  PetscErrorCode ierr;
740
 
741
  PetscFunctionBegin;
742
  PetscValidHeaderSpecific(eps,EPS_COOKIE,1);
743
  PetscValidHeaderSpecific(ip,IP_COOKIE,2);
744
  PetscCheckSameComm(eps,1,ip,2);
745
  ierr = PetscObjectReference((PetscObject)ip);CHKERRQ(ierr);
746
  ierr = IPDestroy(eps->ip); CHKERRQ(ierr);
747
  eps->ip = ip;
748
  PetscFunctionReturn(0);
749
}
750
 
751
#undef __FUNCT__  
752
#define __FUNCT__ "EPSGetIP"
753
/*@C
754
   EPSGetIP - Obtain the inner product object associated
755
   to the eigensolver object.
756
 
757
   Not Collective
758
 
759
   Input Parameters:
760
.  eps - eigensolver context obtained from EPSCreate()
761
 
762
   Output Parameter:
763
.  ip - inner product context
764
 
1349 slepc 765
   Level: advanced
1345 slepc 766
 
767
.seealso: EPSSetIP()
768
@*/
769
PetscErrorCode EPSGetIP(EPS eps,IP *ip)
770
{
771
  PetscFunctionBegin;
772
  PetscValidHeaderSpecific(eps,EPS_COOKIE,1);
773
  PetscValidPointer(ip,2);
774
  *ip = eps->ip;
775
  PetscFunctionReturn(0);
776
}
777
 
778
#undef __FUNCT__  
519 dsic.upv.es!antodo 779
#define __FUNCT__ "EPSIsGeneralized"
780
/*@
781
   EPSIsGeneralized - Ask if the EPS object corresponds to a generalized
782
   eigenvalue problem.
783
 
784
   Not collective
785
 
786
   Input Parameter:
787
.  eps - the eigenproblem solver context
788
 
789
   Output Parameter:
790
.  is - the answer
791
 
792
   Level: intermediate
793
 
794
@*/
795
PetscErrorCode EPSIsGeneralized(EPS eps,PetscTruth* is)
796
{
797
  PetscErrorCode ierr;
798
  Mat            B;
799
 
800
  PetscFunctionBegin;
801
  PetscValidHeaderSpecific(eps,EPS_COOKIE,1);
802
  ierr = STGetOperators(eps->OP,PETSC_NULL,&B);CHKERRQ(ierr);
803
  if( B ) *is = PETSC_TRUE;
804
  else *is = PETSC_FALSE;
805
  if( eps->setupcalled ) {
806
    if( eps->isgeneralized != *is ) {
807
      SETERRQ(0,"Warning: Inconsistent EPS state");
808
    }
809
  }
810
  PetscFunctionReturn(0);
811
}
812
 
813
#undef __FUNCT__  
814
#define __FUNCT__ "EPSIsHermitian"
815
/*@
816
   EPSIsHermitian - Ask if the EPS object corresponds to a Hermitian
817
   eigenvalue problem.
818
 
819
   Not collective
820
 
821
   Input Parameter:
822
.  eps - the eigenproblem solver context
823
 
824
   Output Parameter:
825
.  is - the answer
826
 
827
   Level: intermediate
828
 
829
@*/
830
PetscErrorCode EPSIsHermitian(EPS eps,PetscTruth* is)
831
{
832
  PetscFunctionBegin;
833
  PetscValidHeaderSpecific(eps,EPS_COOKIE,1);
834
  if( eps->ishermitian ) *is = PETSC_TRUE;
835
  else *is = PETSC_FALSE;
836
  PetscFunctionReturn(0);
837
}