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;
2040 eromero 175
        case EPS_HARMONIC_RELATIVE:extr = "relative harmonic Ritz"; break;
176
        case EPS_HARMONIC_RIGHT:   extr = "right harmonic Ritz"; break;
177
        case EPS_HARMONIC_LARGEST: extr = "largest harmonic Ritz"; break;
1560 slepc 178
        case EPS_REFINED:          extr = "refined Ritz"; break;
179
        case EPS_REFINED_HARMONIC: extr = "refined harmonic Ritz"; break;
180
        default: SETERRQ(1,"Wrong value of eps->extraction");
1426 slepc 181
      }
1560 slepc 182
      ierr = PetscViewerASCIIPrintf(viewer,"  extraction type: %s\n",extr);CHKERRQ(ierr);
1426 slepc 183
    }
1940 jroman 184
    if (eps->balance && !eps->ishermitian && eps->balance!=EPS_BALANCE_NONE) {
1799 jroman 185
      switch (eps->balance) {
1940 jroman 186
        case EPS_BALANCE_ONESIDE:   bal = "one-sided Krylov"; break;
187
        case EPS_BALANCE_TWOSIDE:   bal = "two-sided Krylov"; break;
188
        case EPS_BALANCE_USER:      bal = "user-defined matrix"; break;
1799 jroman 189
        default: SETERRQ(1,"Wrong value of eps->balance");
190
      }
1804 jroman 191
      ierr = PetscViewerASCIIPrintf(viewer,"  balancing enabled: %s",bal);CHKERRQ(ierr);
1940 jroman 192
      if (eps->balance==EPS_BALANCE_ONESIDE || eps->balance==EPS_BALANCE_TWOSIDE) {
1804 jroman 193
        ierr = PetscViewerASCIIPrintf(viewer,", with its=%d",eps->balance_its);CHKERRQ(ierr);
194
      }
1940 jroman 195
      if (eps->balance==EPS_BALANCE_TWOSIDE && eps->balance_cutoff!=0.0) {
1799 jroman 196
        ierr = PetscViewerASCIIPrintf(viewer," and cutoff=%g",eps->balance_cutoff);CHKERRQ(ierr);
197
      }
198
      ierr = PetscViewerASCIIPrintf(viewer,"\n");CHKERRQ(ierr);
199
    }
1425 slepc 200
    ierr = PetscViewerASCIIPrintf(viewer,"  selected portion of the spectrum: ");CHKERRQ(ierr);
1942 jroman 201
    if (!eps->which) {
202
      ierr = PetscViewerASCIIPrintf(viewer,"not yet set\n");CHKERRQ(ierr);
203
    } else switch (eps->which) {
1945 jroman 204
      case EPS_WHICH_USER:
1782 antodo 205
        ierr = PetscViewerASCIIPrintf(viewer,"user defined\n");CHKERRQ(ierr);
206
        break;
207
      case EPS_TARGET_MAGNITUDE:
1818 jroman 208
#if !defined(PETSC_USE_COMPLEX)
209
        ierr = PetscViewerASCIIPrintf(viewer,"closest to target: %g (in magnitude)\n",eps->target);CHKERRQ(ierr);
210
#else
211
        ierr = PetscViewerASCIIPrintf(viewer,"closest to target: %g+%g i (in magnitude)\n",PetscRealPart(eps->target),PetscImaginaryPart(eps->target));CHKERRQ(ierr);
212
#endif
213
        break;
1782 antodo 214
      case EPS_TARGET_REAL:
1425 slepc 215
#if !defined(PETSC_USE_COMPLEX)
1818 jroman 216
        ierr = PetscViewerASCIIPrintf(viewer,"closest to target: %g (along the real axis)\n",eps->target);CHKERRQ(ierr);
1425 slepc 217
#else
1818 jroman 218
        ierr = PetscViewerASCIIPrintf(viewer,"closest to target: %g+%g i (along the real axis)\n",PetscRealPart(eps->target),PetscImaginaryPart(eps->target));CHKERRQ(ierr);
1425 slepc 219
#endif
1782 antodo 220
        break;
1818 jroman 221
#if defined(PETSC_USE_COMPLEX)
222
      case EPS_TARGET_IMAGINARY:
223
        ierr = PetscViewerASCIIPrintf(viewer,"closest to target: %g+%g i (along the imaginary axis)\n",PetscRealPart(eps->target),PetscImaginaryPart(eps->target));CHKERRQ(ierr);
224
        break;
225
#endif
226
      case EPS_LARGEST_MAGNITUDE:
227
        ierr = PetscViewerASCIIPrintf(viewer,"largest eigenvalues in magnitude\n");CHKERRQ(ierr);
228
        break;
229
      case EPS_SMALLEST_MAGNITUDE:
230
        ierr = PetscViewerASCIIPrintf(viewer,"smallest eigenvalues in magnitude\n");CHKERRQ(ierr);
231
        break;
232
      case EPS_LARGEST_REAL:
233
        ierr = PetscViewerASCIIPrintf(viewer,"largest real parts\n");CHKERRQ(ierr);
234
        break;
235
      case EPS_SMALLEST_REAL:
236
        ierr = PetscViewerASCIIPrintf(viewer,"smallest real parts\n");CHKERRQ(ierr);
237
        break;
238
      case EPS_LARGEST_IMAGINARY:
239
        ierr = PetscViewerASCIIPrintf(viewer,"largest imaginary parts\n");CHKERRQ(ierr);
240
        break;
241
      case EPS_SMALLEST_IMAGINARY:
242
        ierr = PetscViewerASCIIPrintf(viewer,"smallest imaginary parts\n");CHKERRQ(ierr);
243
        break;
1782 antodo 244
      default: SETERRQ(1,"Wrong value of eps->which");
245
    }    
1944 jroman 246
    if (eps->leftvecs) {
247
      ierr = PetscViewerASCIIPrintf(viewer,"  computing left eigenvectors also\n");CHKERRQ(ierr);
248
    }
2031 jroman 249
    if (eps->trueres) {
250
      ierr = PetscViewerASCIIPrintf(viewer,"  computing true residuals explicitly\n");CHKERRQ(ierr);
251
    }
2041 eromero 252
    if (eps->trackall) {
2046 jroman 253
      ierr = PetscViewerASCIIPrintf(viewer,"  computing all residuals (for tracking convergence)\n");CHKERRQ(ierr);
2041 eromero 254
    }
519 dsic.upv.es!antodo 255
    ierr = PetscViewerASCIIPrintf(viewer,"  number of eigenvalues (nev): %d\n",eps->nev);CHKERRQ(ierr);
600 dsic.upv.es!jroman 256
    ierr = PetscViewerASCIIPrintf(viewer,"  number of column vectors (ncv): %d\n",eps->ncv);CHKERRQ(ierr);
1575 slepc 257
    ierr = PetscViewerASCIIPrintf(viewer,"  maximum dimension of projected problem (mpd): %d\n",eps->mpd);CHKERRQ(ierr);
519 dsic.upv.es!antodo 258
    ierr = PetscViewerASCIIPrintf(viewer,"  maximum number of iterations: %d\n", eps->max_it);
259
    ierr = PetscViewerASCIIPrintf(viewer,"  tolerance: %g\n",eps->tol);CHKERRQ(ierr);
2083 eromero 260
    switch(eps->conv) {
261
    case EPS_CONV_ABS:
262
      ierr = PetscViewerASCIIPrintf(viewer,"  absolute error convergence test\n");CHKERRQ(ierr);break;
263
    case EPS_CONV_EIG:
264
      ierr = PetscViewerASCIIPrintf(viewer,"  eigenvalue relative error convergence test\n");CHKERRQ(ierr);break;
265
    case EPS_CONV_NORM:
266
      ierr = PetscViewerASCIIPrintf(viewer,"  eigenvalue and matrix norm relative error convergence test\n");CHKERRQ(ierr);break;
267
    default:
268
      ierr = PetscViewerASCIIPrintf(viewer,"  user defined convergence test\n");CHKERRQ(ierr);break;
269
    }
1938 jroman 270
    if (eps->nini!=0) {
271
      ierr = PetscViewerASCIIPrintf(viewer,"  dimension of user-provided initial space: %d\n",PetscAbs(eps->nini));CHKERRQ(ierr);
272
    }
273
    if (eps->ninil!=0) {
274
      ierr = PetscViewerASCIIPrintf(viewer,"  dimension of user-provided initial left space: %d\n",PetscAbs(eps->ninil));CHKERRQ(ierr);
275
    }
276
    if (eps->nds>0) {
277
      ierr = PetscViewerASCIIPrintf(viewer,"  dimension of user-provided deflation space: %d\n",eps->nds);CHKERRQ(ierr);
278
    }
1957 jroman 279
    ierr = PetscViewerASCIIPrintf(viewer,"  estimates of matrix norms (%s): norm(A)=%g",eps->adaptive?"adaptive":"constant",eps->nrma);CHKERRQ(ierr);
280
    if (eps->isgeneralized) {
281
      ierr = PetscViewerASCIIPrintf(viewer,", norm(B)=%g",eps->nrmb);CHKERRQ(ierr);
282
    }
283
    ierr = PetscViewerASCIIPrintf(viewer,"\n");CHKERRQ(ierr);
519 dsic.upv.es!antodo 284
    ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
1345 slepc 285
    ierr = IPView(eps->ip,viewer); CHKERRQ(ierr);
519 dsic.upv.es!antodo 286
    ierr = STView(eps->OP,viewer); CHKERRQ(ierr);
287
    ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
288
  } else {
289
    if (eps->ops->view) {
290
      ierr = (*eps->ops->view)(eps,viewer);CHKERRQ(ierr);
291
    }
292
    ierr = STView(eps->OP,viewer); CHKERRQ(ierr);
293
  }
294
  PetscFunctionReturn(0);
295
}
296
 
297
#undef __FUNCT__  
298
#define __FUNCT__ "EPSCreate"
299
/*@C
300
   EPSCreate - Creates the default EPS context.
301
 
302
   Collective on MPI_Comm
303
 
304
   Input Parameter:
305
.  comm - MPI communicator
306
 
307
   Output Parameter:
308
.  eps - location to put the EPS context
309
 
310
   Note:
1198 slepc 311
   The default EPS type is EPSKRYLOVSCHUR
519 dsic.upv.es!antodo 312
 
313
   Level: beginner
314
 
315
.seealso: EPSSetUp(), EPSSolve(), EPSDestroy(), EPS
316
@*/
317
PetscErrorCode EPSCreate(MPI_Comm comm,EPS *outeps)
318
{
319
  PetscErrorCode ierr;
320
  EPS            eps;
321
 
322
  PetscFunctionBegin;
323
  PetscValidPointer(outeps,2);
324
  *outeps = 0;
325
 
1454 slepc 326
  ierr = PetscHeaderCreate(eps,_p_EPS,struct _EPSOps,EPS_COOKIE,-1,"EPS",comm,EPSDestroy,EPSView);CHKERRQ(ierr);
519 dsic.upv.es!antodo 327
  *outeps = eps;
328
 
329
  ierr = PetscMemzero(eps->ops,sizeof(struct _EPSOps));CHKERRQ(ierr);
330
 
331
  eps->max_it          = 0;
332
  eps->nev             = 1;
333
  eps->ncv             = 0;
1575 slepc 334
  eps->mpd             = 0;
519 dsic.upv.es!antodo 335
  eps->allocated_ncv   = 0;
1932 jroman 336
  eps->nini            = 0;
1937 jroman 337
  eps->ninil           = 0;
519 dsic.upv.es!antodo 338
  eps->nds             = 0;
1282 slepc 339
  eps->tol             = 1e-7;
2083 eromero 340
  eps->conv_func       = EPSEigRelativeConverged;
1785 antodo 341
  eps->conv_ctx        = PETSC_NULL;
1942 jroman 342
  eps->which           = (EPSWhich)0;
1782 antodo 343
  eps->which_func      = PETSC_NULL;
344
  eps->which_ctx       = PETSC_NULL;
1944 jroman 345
  eps->leftvecs        = PETSC_FALSE;
2031 jroman 346
  eps->trueres         = PETSC_FALSE;
2041 eromero 347
  eps->trackall        = PETSC_FALSE;
1425 slepc 348
  eps->target          = 0.0;
519 dsic.upv.es!antodo 349
  eps->evecsavailable  = PETSC_FALSE;
350
  eps->problem_type    = (EPSProblemType)0;
1560 slepc 351
  eps->extraction      = (EPSExtraction)0;
1799 jroman 352
  eps->balance         = (EPSBalance)0;
353
  eps->balance_its     = 5;
354
  eps->balance_cutoff  = 1e-8;
1957 jroman 355
  eps->nrma            = 1.0;
356
  eps->nrmb            = 1.0;
357
  eps->adaptive        = PETSC_FALSE;
519 dsic.upv.es!antodo 358
 
359
  eps->V               = 0;
780 dsic.upv.es!jroman 360
  eps->W               = 0;
519 dsic.upv.es!antodo 361
  eps->T               = 0;
362
  eps->DS              = 0;
1937 jroman 363
  eps->IS              = 0;
364
  eps->ISL             = 0;
1917 jroman 365
  eps->ds_ortho        = PETSC_FALSE;
519 dsic.upv.es!antodo 366
  eps->eigr            = 0;
367
  eps->eigi            = 0;
368
  eps->errest          = 0;
780 dsic.upv.es!jroman 369
  eps->errest_left     = 0;
519 dsic.upv.es!antodo 370
  eps->OP              = 0;
1345 slepc 371
  eps->ip              = 0;
519 dsic.upv.es!antodo 372
  eps->data            = 0;
373
  eps->nconv           = 0;
374
  eps->its             = 0;
375
  eps->perm            = PETSC_NULL;
376
 
377
  eps->nwork           = 0;
378
  eps->work            = 0;
379
  eps->isgeneralized   = PETSC_FALSE;
380
  eps->ishermitian     = PETSC_FALSE;
1358 slepc 381
  eps->ispositive      = PETSC_FALSE;
519 dsic.upv.es!antodo 382
  eps->setupcalled     = 0;
383
  eps->reason          = EPS_CONVERGED_ITERATING;
384
 
385
  eps->numbermonitors  = 0;
386
 
387
  ierr = STCreate(comm,&eps->OP); CHKERRQ(ierr);
388
  PetscLogObjectParent(eps,eps->OP);
1345 slepc 389
  ierr = IPCreate(comm,&eps->ip); CHKERRQ(ierr);
1422 slepc 390
  ierr = IPSetOptionsPrefix(eps->ip,((PetscObject)eps)->prefix);
1345 slepc 391
  ierr = IPAppendOptionsPrefix(eps->ip,"eps_");
392
  PetscLogObjectParent(eps,eps->ip);
519 dsic.upv.es!antodo 393
  ierr = PetscPublishAll(eps);CHKERRQ(ierr);
394
  PetscFunctionReturn(0);
395
}
396
 
397
#undef __FUNCT__  
398
#define __FUNCT__ "EPSSetType"
399
/*@C
400
   EPSSetType - Selects the particular solver to be used in the EPS object.
401
 
402
   Collective on EPS
403
 
404
   Input Parameters:
405
+  eps      - the eigensolver context
406
-  type     - a known method
407
 
408
   Options Database Key:
409
.  -eps_type <method> - Sets the method; use -help for a list
410
    of available methods
411
 
412
   Notes:  
545 dsic.upv.es!jroman 413
   See "slepc/include/slepceps.h" for available methods. The default
1198 slepc 414
   is EPSKRYLOVSCHUR.
519 dsic.upv.es!antodo 415
 
416
   Normally, it is best to use the EPSSetFromOptions() command and
417
   then set the EPS type from the options database rather than by using
418
   this routine.  Using the options database provides the user with
419
   maximum flexibility in evaluating the different available methods.
420
   The EPSSetType() routine is provided for those situations where it
421
   is necessary to set the iterative solver independently of the command
422
   line or options database.
423
 
424
   Level: intermediate
425
 
426
.seealso: STSetType(), EPSType
427
@*/
1502 slepc 428
PetscErrorCode EPSSetType(EPS eps,const EPSType type)
519 dsic.upv.es!antodo 429
{
430
  PetscErrorCode ierr,(*r)(EPS);
431
  PetscTruth match;
432
 
433
  PetscFunctionBegin;
434
  PetscValidHeaderSpecific(eps,EPS_COOKIE,1);
435
  PetscValidCharPointer(type,2);
436
 
437
  ierr = PetscTypeCompare((PetscObject)eps,type,&match);CHKERRQ(ierr);
438
  if (match) PetscFunctionReturn(0);
439
 
440
  if (eps->data) {
441
    /* destroy the old private EPS context */
442
    ierr = (*eps->ops->destroy)(eps); CHKERRQ(ierr);
443
    eps->data = 0;
444
  }
445
 
1422 slepc 446
  ierr = PetscFListFind(EPSList,((PetscObject)eps)->comm,type,(void (**)(void)) &r);CHKERRQ(ierr);
519 dsic.upv.es!antodo 447
 
448
  if (!r) SETERRQ1(1,"Unknown EPS type given: %s",type);
449
 
450
  eps->setupcalled = 0;
451
  ierr = PetscMemzero(eps->ops,sizeof(struct _EPSOps));CHKERRQ(ierr);
452
  ierr = (*r)(eps); CHKERRQ(ierr);
453
 
454
  ierr = PetscObjectChangeTypeName((PetscObject)eps,type);CHKERRQ(ierr);
455
  PetscFunctionReturn(0);
456
}
457
 
458
#undef __FUNCT__  
459
#define __FUNCT__ "EPSGetType"
460
/*@C
461
   EPSGetType - Gets the EPS type as a string from the EPS object.
462
 
463
   Not Collective
464
 
465
   Input Parameter:
466
.  eps - the eigensolver context
467
 
468
   Output Parameter:
469
.  name - name of EPS method
470
 
471
   Level: intermediate
472
 
473
.seealso: EPSSetType()
474
@*/
1501 slepc 475
PetscErrorCode EPSGetType(EPS eps,const EPSType *type)
519 dsic.upv.es!antodo 476
{
477
  PetscFunctionBegin;
478
  PetscValidHeaderSpecific(eps,EPS_COOKIE,1);
1501 slepc 479
  PetscValidPointer(type,2);
1422 slepc 480
  *type = ((PetscObject)eps)->type_name;
519 dsic.upv.es!antodo 481
  PetscFunctionReturn(0);
482
}
483
 
484
/*MC
485
   EPSRegisterDynamic - Adds a method to the eigenproblem solver package.
486
 
487
   Synopsis:
1509 slepc 488
   EPSRegisterDynamic(char *name_solver,char *path,char *name_create,PetscErrorCode (*routine_create)(EPS))
519 dsic.upv.es!antodo 489
 
490
   Not Collective
491
 
492
   Input Parameters:
493
+  name_solver - name of a new user-defined solver
494
.  path - path (either absolute or relative) the library containing this solver
495
.  name_create - name of routine to create the solver context
496
-  routine_create - routine to create the solver context
497
 
498
   Notes:
499
   EPSRegisterDynamic() may be called multiple times to add several user-defined solvers.
500
 
501
   If dynamic libraries are used, then the fourth input argument (routine_create)
502
   is ignored.
503
 
504
   Sample usage:
505
.vb
506
   EPSRegisterDynamic("my_solver",/home/username/my_lib/lib/libO/solaris/mylib.a,
507
               "MySolverCreate",MySolverCreate);
508
.ve
509
 
510
   Then, your solver can be chosen with the procedural interface via
511
$     EPSSetType(eps,"my_solver")
512
   or at runtime via the option
513
$     -eps_type my_solver
514
 
515
   Level: advanced
516
 
1389 slepc 517
   Environmental variables such as ${PETSC_ARCH}, ${PETSC_DIR}, ${PETSC_LIB_DIR},
519 dsic.upv.es!antodo 518
   and others of the form ${any_environmental_variable} occuring in pathname will be
519
   replaced with appropriate values.
520
 
1389 slepc 521
.seealso: EPSRegisterDestroy(), EPSRegisterAll()
519 dsic.upv.es!antodo 522
 
523
M*/
524
 
525
#undef __FUNCT__  
526
#define __FUNCT__ "EPSRegister"
1389 slepc 527
/*@C
528
  EPSRegister - See EPSRegisterDynamic()
529
 
530
  Level: advanced
531
@*/
1509 slepc 532
PetscErrorCode EPSRegister(const char *sname,const char *path,const char *name,PetscErrorCode (*function)(EPS))
519 dsic.upv.es!antodo 533
{
534
  PetscErrorCode ierr;
535
  char           fullname[256];
536
 
537
  PetscFunctionBegin;
538
  ierr = PetscFListConcat(path,name,fullname);CHKERRQ(ierr);
539
  ierr = PetscFListAdd(&EPSList,sname,fullname,(void (*)(void))function);CHKERRQ(ierr);
540
  PetscFunctionReturn(0);
541
}
542
 
543
#undef __FUNCT__  
1389 slepc 544
#define __FUNCT__ "EPSRegisterDestroy"
545
/*@
546
   EPSRegisterDestroy - Frees the list of EPS methods that were
547
   registered by EPSRegisterDynamic().
548
 
549
   Not Collective
550
 
551
   Level: advanced
552
 
553
.seealso: EPSRegisterDynamic(), EPSRegisterAll()
554
@*/
555
PetscErrorCode EPSRegisterDestroy(void)
556
{
557
  PetscErrorCode ierr;
558
 
559
  PetscFunctionBegin;
560
  ierr = PetscFListDestroy(&EPSList);CHKERRQ(ierr);
561
  ierr = EPSRegisterAll(PETSC_NULL);CHKERRQ(ierr);
562
  PetscFunctionReturn(0);
563
}
564
 
565
#undef __FUNCT__  
519 dsic.upv.es!antodo 566
#define __FUNCT__ "EPSDestroy"
567
/*@
568
   EPSDestroy - Destroys the EPS context.
569
 
570
   Collective on EPS
571
 
572
   Input Parameter:
573
.  eps - eigensolver context obtained from EPSCreate()
574
 
575
   Level: beginner
576
 
577
.seealso: EPSCreate(), EPSSetUp(), EPSSolve()
578
@*/
579
PetscErrorCode EPSDestroy(EPS eps)
580
{
581
  PetscErrorCode ierr;
582
 
583
  PetscFunctionBegin;
584
  PetscValidHeaderSpecific(eps,EPS_COOKIE,1);
1422 slepc 585
  if (--((PetscObject)eps)->refct > 0) PetscFunctionReturn(0);
519 dsic.upv.es!antodo 586
 
587
  /* if memory was published with AMS then destroy it */
588
  ierr = PetscObjectDepublish(eps);CHKERRQ(ierr);
589
 
590
  ierr = STDestroy(eps->OP);CHKERRQ(ierr);
1345 slepc 591
  ierr = IPDestroy(eps->ip);CHKERRQ(ierr);
519 dsic.upv.es!antodo 592
 
593
  if (eps->ops->destroy) {
594
    ierr = (*eps->ops->destroy)(eps); CHKERRQ(ierr);
595
  }
596
 
1040 slepc 597
  ierr = PetscFree(eps->T);CHKERRQ(ierr);
598
  ierr = PetscFree(eps->Tl);CHKERRQ(ierr);
599
  ierr = PetscFree(eps->perm);CHKERRQ(ierr);
2027 jroman 600
  ierr = PetscRandomDestroy(eps->rand);CHKERRQ(ierr);
519 dsic.upv.es!antodo 601
 
1800 jroman 602
  if (eps->D) {
603
    ierr = VecDestroy(eps->D);CHKERRQ(ierr);
604
  }
605
 
1917 jroman 606
  ierr = EPSRemoveDeflationSpace(eps);CHKERRQ(ierr);
1331 slepc 607
  ierr = EPSMonitorCancel(eps);CHKERRQ(ierr);
1287 slepc 608
 
1570 slepc 609
  ierr = PetscHeaderDestroy(eps);CHKERRQ(ierr);
519 dsic.upv.es!antodo 610
  PetscFunctionReturn(0);
611
}
612
 
613
#undef __FUNCT__  
1425 slepc 614
#define __FUNCT__ "EPSSetTarget"
615
/*@
616
   EPSSetTarget - Sets the value of the target.
617
 
1811 jroman 618
   Collective on EPS
1425 slepc 619
 
620
   Input Parameters:
621
+  eps    - eigensolver context
622
-  target - the value of the target
623
 
624
   Notes:
625
   The target is a scalar value used to determine the portion of the spectrum
1811 jroman 626
   of interest. It is used in combination with EPSSetWhichEigenpairs().
1425 slepc 627
 
628
   Level: beginner
629
 
630
.seealso: EPSGetTarget(), EPSSetWhichEigenpairs()
631
@*/
632
PetscErrorCode EPSSetTarget(EPS eps,PetscScalar target)
633
{
2074 jroman 634
  PetscErrorCode ierr;
635
 
1425 slepc 636
  PetscFunctionBegin;
637
  PetscValidHeaderSpecific(eps,EPS_COOKIE,1);
638
  eps->target = target;
2074 jroman 639
  ierr = STSetDefaultShift(eps->OP,target);CHKERRQ(ierr);
1425 slepc 640
  PetscFunctionReturn(0);
641
}
642
 
643
#undef __FUNCT__  
644
#define __FUNCT__ "EPSGetTarget"
645
/*@
646
   EPSGetTarget - Gets the value of the target.
647
 
648
   Not collective
649
 
650
   Input Parameter:
651
.  eps - eigensolver context
652
 
653
   Output Parameter:
654
.  target - the value of the target
655
 
656
   Level: beginner
657
 
658
   Note:
659
   If the target was not set by the user, then zero is returned.
660
 
661
.seealso: EPSSetTarget()
662
@*/
663
PetscErrorCode EPSGetTarget(EPS eps,PetscScalar* target)
664
{
665
  PetscFunctionBegin;
666
  PetscValidHeaderSpecific(eps,EPS_COOKIE,1);
667
  if (target) {
1782 antodo 668
    *target = eps->target;
1425 slepc 669
  }
670
  PetscFunctionReturn(0);
671
}
672
 
673
#undef __FUNCT__  
519 dsic.upv.es!antodo 674
#define __FUNCT__ "EPSSetST"
675
/*@
676
   EPSSetST - Associates a spectral transformation object to the
677
   eigensolver.
678
 
1811 jroman 679
   Collective on EPS and ST
519 dsic.upv.es!antodo 680
 
681
   Input Parameters:
682
+  eps - eigensolver context obtained from EPSCreate()
683
-  st   - the spectral transformation object
684
 
685
   Note:
686
   Use EPSGetST() to retrieve the spectral transformation context (for example,
687
   to free it at the end of the computations).
688
 
689
   Level: advanced
690
 
691
.seealso: EPSGetST()
692
@*/
693
PetscErrorCode EPSSetST(EPS eps,ST st)
694
{
695
  PetscErrorCode ierr;
696
 
697
  PetscFunctionBegin;
698
  PetscValidHeaderSpecific(eps,EPS_COOKIE,1);
699
  PetscValidHeaderSpecific(st,ST_COOKIE,2);
700
  PetscCheckSameComm(eps,1,st,2);
1345 slepc 701
  ierr = PetscObjectReference((PetscObject)st);CHKERRQ(ierr);
519 dsic.upv.es!antodo 702
  ierr = STDestroy(eps->OP); CHKERRQ(ierr);
703
  eps->OP = st;
704
  PetscFunctionReturn(0);
705
}
706
 
707
#undef __FUNCT__  
708
#define __FUNCT__ "EPSGetST"
707 dsic.upv.es!antodo 709
/*@C
519 dsic.upv.es!antodo 710
   EPSGetST - Obtain the spectral transformation (ST) object associated
711
   to the eigensolver object.
712
 
713
   Not Collective
714
 
715
   Input Parameters:
716
.  eps - eigensolver context obtained from EPSCreate()
717
 
718
   Output Parameter:
719
.  st - spectral transformation context
720
 
721
   Level: beginner
722
 
723
.seealso: EPSSetST()
724
@*/
725
PetscErrorCode EPSGetST(EPS eps, ST *st)
726
{
727
  PetscFunctionBegin;
728
  PetscValidHeaderSpecific(eps,EPS_COOKIE,1);
1248 slepc 729
  PetscValidPointer(st,2);
519 dsic.upv.es!antodo 730
  *st = eps->OP;
731
  PetscFunctionReturn(0);
732
}
733
 
734
#undef __FUNCT__  
1345 slepc 735
#define __FUNCT__ "EPSSetIP"
736
/*@
1811 jroman 737
   EPSSetIP - Associates an inner product object to the eigensolver.
1345 slepc 738
 
1811 jroman 739
   Collective on EPS and IP
1345 slepc 740
 
741
   Input Parameters:
742
+  eps - eigensolver context obtained from EPSCreate()
743
-  ip  - the inner product object
744
 
745
   Note:
746
   Use EPSGetIP() to retrieve the inner product context (for example,
747
   to free it at the end of the computations).
748
 
749
   Level: advanced
750
 
751
.seealso: EPSGetIP()
752
@*/
753
PetscErrorCode EPSSetIP(EPS eps,IP ip)
754
{
755
  PetscErrorCode ierr;
756
 
757
  PetscFunctionBegin;
758
  PetscValidHeaderSpecific(eps,EPS_COOKIE,1);
759
  PetscValidHeaderSpecific(ip,IP_COOKIE,2);
760
  PetscCheckSameComm(eps,1,ip,2);
761
  ierr = PetscObjectReference((PetscObject)ip);CHKERRQ(ierr);
762
  ierr = IPDestroy(eps->ip); CHKERRQ(ierr);
763
  eps->ip = ip;
764
  PetscFunctionReturn(0);
765
}
766
 
767
#undef __FUNCT__  
768
#define __FUNCT__ "EPSGetIP"
769
/*@C
770
   EPSGetIP - Obtain the inner product object associated
771
   to the eigensolver object.
772
 
773
   Not Collective
774
 
775
   Input Parameters:
776
.  eps - eigensolver context obtained from EPSCreate()
777
 
778
   Output Parameter:
779
.  ip - inner product context
780
 
1349 slepc 781
   Level: advanced
1345 slepc 782
 
783
.seealso: EPSSetIP()
784
@*/
785
PetscErrorCode EPSGetIP(EPS eps,IP *ip)
786
{
787
  PetscFunctionBegin;
788
  PetscValidHeaderSpecific(eps,EPS_COOKIE,1);
789
  PetscValidPointer(ip,2);
790
  *ip = eps->ip;
791
  PetscFunctionReturn(0);
792
}
793
 
794
#undef __FUNCT__  
519 dsic.upv.es!antodo 795
#define __FUNCT__ "EPSIsGeneralized"
796
/*@
797
   EPSIsGeneralized - Ask if the EPS object corresponds to a generalized
798
   eigenvalue problem.
799
 
800
   Not collective
801
 
802
   Input Parameter:
803
.  eps - the eigenproblem solver context
804
 
805
   Output Parameter:
806
.  is - the answer
807
 
808
   Level: intermediate
809
 
810
@*/
811
PetscErrorCode EPSIsGeneralized(EPS eps,PetscTruth* is)
812
{
813
  PetscErrorCode ierr;
814
  Mat            B;
815
 
816
  PetscFunctionBegin;
817
  PetscValidHeaderSpecific(eps,EPS_COOKIE,1);
818
  ierr = STGetOperators(eps->OP,PETSC_NULL,&B);CHKERRQ(ierr);
819
  if( B ) *is = PETSC_TRUE;
820
  else *is = PETSC_FALSE;
821
  if( eps->setupcalled ) {
822
    if( eps->isgeneralized != *is ) {
823
      SETERRQ(0,"Warning: Inconsistent EPS state");
824
    }
825
  }
826
  PetscFunctionReturn(0);
827
}
828
 
829
#undef __FUNCT__  
830
#define __FUNCT__ "EPSIsHermitian"
831
/*@
832
   EPSIsHermitian - Ask if the EPS object corresponds to a Hermitian
833
   eigenvalue problem.
834
 
835
   Not collective
836
 
837
   Input Parameter:
838
.  eps - the eigenproblem solver context
839
 
840
   Output Parameter:
841
.  is - the answer
842
 
843
   Level: intermediate
844
 
845
@*/
846
PetscErrorCode EPSIsHermitian(EPS eps,PetscTruth* is)
847
{
848
  PetscFunctionBegin;
849
  PetscValidHeaderSpecific(eps,EPS_COOKIE,1);
850
  if( eps->ishermitian ) *is = PETSC_TRUE;
851
  else *is = PETSC_FALSE;
852
  PetscFunctionReturn(0);
853
}