Subversion Repositories slepc-dev

Rev

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