Subversion Repositories slepc-dev

Rev

Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
545 dsic.upv.es!jroman 1
/*
2
      EPS routines related to problem setup.
1376 slepc 3
 
4
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1672 slepc 5
   SLEPc - Scalable Library for Eigenvalue Problem Computations
2575 eromero 6
   Copyright (c) 2002-2011, Universitat 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
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
545 dsic.upv.es!jroman 22
*/
1376 slepc 23
 
2729 jroman 24
#include <slepc-private/epsimpl.h>       /*I "slepceps.h" I*/
25
#include <slepc-private/ipimpl.h>
527 dsic.upv.es!antodo 26
 
27
#undef __FUNCT__  
28
#define __FUNCT__ "EPSSetUp"
29
/*@
30
   EPSSetUp - Sets up all the internal data structures necessary for the
31
   execution of the eigensolver. Then calls STSetUp() for any set-up
32
   operations associated to the ST object.
33
 
34
   Collective on EPS
35
 
36
   Input Parameter:
37
.  eps   - eigenproblem solver context
38
 
39
   Notes:
40
   This function need not be called explicitly in most cases, since EPSSolve()
41
   calls it. It can be useful when one wants to measure the set-up time
42
   separately from the solve time.
43
 
1811 jroman 44
   Level: advanced
45
 
1933 jroman 46
.seealso: EPSCreate(), EPSSolve(), EPSDestroy(), STSetUp(), EPSSetInitialSpace()
527 dsic.upv.es!antodo 47
@*/
48
PetscErrorCode EPSSetUp(EPS eps)
49
{
50
  PetscErrorCode ierr;
51
  Mat            A,B;
1932 jroman 52
  PetscInt       i,k;
2216 jroman 53
  PetscBool      flg,lindep;
2359 jroman 54
  Vec            *newDS;
1932 jroman 55
  PetscReal      norm;
1849 antodo 56
#if defined(PETSC_USE_COMPLEX)
57
  PetscScalar    sigma;
58
#endif
527 dsic.upv.es!antodo 59
 
60
  PetscFunctionBegin;
2213 jroman 61
  PetscValidHeaderSpecific(eps,EPS_CLASSID,1);
527 dsic.upv.es!antodo 62
  if (eps->setupcalled) PetscFunctionReturn(0);
63
  ierr = PetscLogEventBegin(EPS_SetUp,eps,0,0,0);CHKERRQ(ierr);
64
 
2412 jroman 65
  /* Set default solver type (EPSSetFromOptions was not called) */
1422 slepc 66
  if (!((PetscObject)eps)->type_name) {
1198 slepc 67
    ierr = EPSSetType(eps,EPSKRYLOVSCHUR);CHKERRQ(ierr);
527 dsic.upv.es!antodo 68
  }
2412 jroman 69
  if (!eps->OP) { ierr = EPSGetST(eps,&eps->OP);CHKERRQ(ierr); }
70
  if (!((PetscObject)eps->OP)->type_name) {
2823 jroman 71
    ierr = PetscObjectTypeCompareAny((PetscObject)eps,&flg,EPSGD,EPSJD,"");CHKERRQ(ierr);
2616 eromero 72
    ierr = STSetType(eps->OP,flg?STPRECOND:STSHIFT);CHKERRQ(ierr);
2412 jroman 73
  }
74
  if (!eps->ip) { ierr = EPSGetIP(eps,&eps->ip);CHKERRQ(ierr); }
75
  if (!((PetscObject)eps->ip)->type_name) {
76
    ierr = IPSetDefaultType_Private(eps->ip);CHKERRQ(ierr);
77
  }
2758 jroman 78
  if (!eps->ps) { ierr = EPSGetPS(eps,&eps->ps);CHKERRQ(ierr); }
2453 eromero 79
  if (!((PetscObject)eps->rand)->type_name) {
80
    ierr = PetscRandomSetFromOptions(eps->rand);CHKERRQ(ierr);
81
  }
691 dsic.upv.es!antodo 82
 
1928 jroman 83
  /* Set problem dimensions */
527 dsic.upv.es!antodo 84
  ierr = STGetOperators(eps->OP,&A,&B);CHKERRQ(ierr);
2350 jroman 85
  if (!A) SETERRQ(((PetscObject)eps)->comm,PETSC_ERR_ARG_WRONGSTATE,"EPSSetOperators must be called first");
1928 jroman 86
  ierr = MatGetSize(A,&eps->n,PETSC_NULL);CHKERRQ(ierr);
87
  ierr = MatGetLocalSize(A,&eps->nloc,PETSC_NULL);CHKERRQ(ierr);
2507 jroman 88
  ierr = VecDestroy(&eps->t);CHKERRQ(ierr);
2410 jroman 89
  ierr = SlepcMatGetVecsTemplate(A,&eps->t,PETSC_NULL);CHKERRQ(ierr);
1928 jroman 90
 
527 dsic.upv.es!antodo 91
  /* Set default problem type */
92
  if (!eps->problem_type) {
93
    if (B==PETSC_NULL) {
94
      ierr = EPSSetProblemType(eps,EPS_NHEP);CHKERRQ(ierr);
2348 jroman 95
    } else {
527 dsic.upv.es!antodo 96
      ierr = EPSSetProblemType(eps,EPS_GNHEP);CHKERRQ(ierr);
97
    }
2498 jroman 98
  } else if (!B && eps->isgeneralized) {
99
    ierr = PetscInfo(eps,"Eigenproblem set as generalized but no matrix B was provided; reverting to a standard eigenproblem\n");CHKERRQ(ierr);
100
    eps->isgeneralized = PETSC_FALSE;
101
    eps->problem_type = eps->ishermitian? EPS_HEP: EPS_NHEP;
2762 jroman 102
  } else if (B && !eps->isgeneralized) SETERRQ(((PetscObject)eps)->comm,PETSC_ERR_ARG_INCOMP,"Inconsistent EPS state");
1849 antodo 103
#if defined(PETSC_USE_COMPLEX)
104
  ierr = STGetShift(eps->OP,&sigma);CHKERRQ(ierr);
2762 jroman 105
  if (eps->ishermitian && PetscImaginaryPart(sigma) != 0.0) SETERRQ(((PetscObject)eps)->comm,1,"Hermitian problems are not compatible with complex shifts");
1849 antodo 106
#endif
2762 jroman 107
  if (eps->ishermitian && eps->leftvecs) SETERRQ(((PetscObject)eps)->comm,1,"Requesting left eigenvectors not allowed in Hermitian problems");
527 dsic.upv.es!antodo 108
 
2742 carcamgo 109
  if (eps->ispositive || (eps->isgeneralized && eps->ishermitian)) {
1358 slepc 110
    ierr = STGetBilinearForm(eps->OP,&B);CHKERRQ(ierr);
2380 jroman 111
    ierr = IPSetMatrix(eps->ip,B);CHKERRQ(ierr);
2305 jroman 112
    ierr = MatDestroy(&B);CHKERRQ(ierr);
2747 jroman 113
    if (!eps->ispositive) { ierr = IPSetType(eps->ip,IPINDEFINITE);CHKERRQ(ierr); }
1358 slepc 114
  } else {
2380 jroman 115
    ierr = IPSetMatrix(eps->ip,PETSC_NULL);CHKERRQ(ierr);
1358 slepc 116
  }
117
 
1928 jroman 118
  if (eps->nev > eps->n) eps->nev = eps->n;
119
  if (eps->ncv > eps->n) eps->ncv = eps->n;
1220 slepc 120
 
1957 jroman 121
  /* initialization of matrix norms */
122
  if (eps->nrma == PETSC_DETERMINE) {
123
    ierr = MatHasOperation(A,MATOP_NORM,&flg);CHKERRQ(ierr);
124
    if (flg) { ierr = MatNorm(A,NORM_INFINITY,&eps->nrma);CHKERRQ(ierr); }
125
    else eps->nrma = 1.0;
126
  }
127
  if (eps->nrmb == PETSC_DETERMINE) {
128
    ierr = MatHasOperation(B,MATOP_NORM,&flg);CHKERRQ(ierr);
129
    if (flg) { ierr = MatNorm(B,NORM_INFINITY,&eps->nrmb);CHKERRQ(ierr); }
130
    else eps->nrmb = 1.0;
131
  }
132
 
2653 jroman 133
  if (!eps->balance) eps->balance = EPS_BALANCE_NONE;
134
 
1957 jroman 135
  /* call specific solver setup */
527 dsic.upv.es!antodo 136
  ierr = (*eps->ops->setup)(eps);CHKERRQ(ierr);
2348 jroman 137
 
2619 jroman 138
  /* set tolerance if not yet set */
139
  if (eps->tol==PETSC_DEFAULT) eps->tol = SLEPC_DEFAULT_TOL;
140
 
2760 jroman 141
  /* set eigenvalue comparison */
142
  switch (eps->which) {
143
    case EPS_LARGEST_MAGNITUDE:
144
      eps->which_func = SlepcCompareLargestMagnitude;
145
      eps->which_ctx  = PETSC_NULL;
146
      break;
147
    case EPS_SMALLEST_MAGNITUDE:
148
      eps->which_func = SlepcCompareSmallestMagnitude;
149
      eps->which_ctx  = PETSC_NULL;
150
      break;
151
    case EPS_LARGEST_REAL:
152
      eps->which_func = SlepcCompareLargestReal;
153
      eps->which_ctx  = PETSC_NULL;
154
      break;
155
    case EPS_SMALLEST_REAL:
156
      eps->which_func = SlepcCompareSmallestReal;
157
      eps->which_ctx  = PETSC_NULL;
158
      break;
159
    case EPS_LARGEST_IMAGINARY:
160
      eps->which_func = SlepcCompareLargestImaginary;
161
      eps->which_ctx  = PETSC_NULL;
162
      break;
163
    case EPS_SMALLEST_IMAGINARY:
164
      eps->which_func = SlepcCompareSmallestImaginary;
165
      eps->which_ctx  = PETSC_NULL;
166
      break;
167
    case EPS_TARGET_MAGNITUDE:
168
      eps->which_func = SlepcCompareTargetMagnitude;
169
      eps->which_ctx  = &eps->target;
170
      break;
171
    case EPS_TARGET_REAL:
172
      eps->which_func = SlepcCompareTargetReal;
173
      eps->which_ctx  = &eps->target;
174
      break;
175
    case EPS_TARGET_IMAGINARY:
176
      eps->which_func = SlepcCompareTargetImaginary;
177
      eps->which_ctx  = &eps->target;
178
      break;
179
    case EPS_ALL:
2802 jroman 180
      eps->which_func = SlepcCompareSmallestReal;
2760 jroman 181
      eps->which_ctx  = PETSC_NULL;
182
      break;
183
    case EPS_WHICH_USER:
184
      break;
185
  }
186
 
2348 jroman 187
  /* Build balancing matrix if required */
188
  if (!eps->ishermitian && (eps->balance==EPS_BALANCE_ONESIDE || eps->balance==EPS_BALANCE_TWOSIDE)) {
189
    if (!eps->D) {
190
      ierr = VecDuplicate(eps->V[0],&eps->D);CHKERRQ(ierr);
191
    } else {
192
      ierr = VecSet(eps->D,1.0);CHKERRQ(ierr);
193
    }
194
    ierr = EPSBuildBalance_Krylov(eps);CHKERRQ(ierr);
195
    ierr = STSetBalanceMatrix(eps->OP,eps->D);CHKERRQ(ierr);
196
  }
197
 
198
  /* Setup ST */
2330 jroman 199
  ierr = STSetUp(eps->OP);CHKERRQ(ierr);
527 dsic.upv.es!antodo 200
 
2823 jroman 201
  ierr = PetscObjectTypeCompare((PetscObject)eps->OP,STCAYLEY,&flg);CHKERRQ(ierr);
2762 jroman 202
  if (flg && eps->problem_type == EPS_PGNHEP) SETERRQ(((PetscObject)eps)->comm,PETSC_ERR_SUP,"Cayley spectral transformation is not compatible with PGNHEP");
1789 antodo 203
 
2823 jroman 204
  ierr = PetscObjectTypeCompare((PetscObject)eps->OP,STFOLD,&flg);CHKERRQ(ierr);
2762 jroman 205
  if (flg && !eps->ishermitian) SETERRQ(((PetscObject)eps)->comm,PETSC_ERR_SUP,"Fold spectral transformation requires a Hermitian problem");
2087 jroman 206
 
527 dsic.upv.es!antodo 207
  if (eps->nds>0) {
208
    if (!eps->ds_ortho) {
1917 jroman 209
      /* allocate memory and copy deflation basis vectors into DS */
2410 jroman 210
      ierr = VecDuplicateVecs(eps->t,eps->nds,&newDS);CHKERRQ(ierr);
1917 jroman 211
      for (i=0;i<eps->nds;i++) {
2359 jroman 212
        ierr = VecCopy(eps->DS[i],newDS[i]);CHKERRQ(ierr);
2305 jroman 213
        ierr = VecDestroy(&eps->DS[i]);CHKERRQ(ierr);
1917 jroman 214
      }
2359 jroman 215
      ierr = PetscFree(eps->DS);CHKERRQ(ierr);
216
      eps->DS = newDS;
1917 jroman 217
      /* orthonormalize vectors in DS */
1954 jroman 218
      k = 0;
219
      for (i=0;i<eps->nds;i++) {
220
        ierr = IPOrthogonalize(eps->ip,0,PETSC_NULL,k,PETSC_NULL,eps->DS,eps->DS[k],PETSC_NULL,&norm,&lindep);CHKERRQ(ierr);
2499 jroman 221
        if (norm==0.0 || lindep) {
222
          ierr = PetscInfo(eps,"Linearly dependent deflation vector found, removing...\n");CHKERRQ(ierr);
223
        } else {
1954 jroman 224
          ierr = VecScale(eps->DS[k],1.0/norm);CHKERRQ(ierr);
225
          k++;
226
        }
227
      }
2359 jroman 228
      for (i=k;i<eps->nds;i++) { ierr = VecDestroy(&eps->DS[i]);CHKERRQ(ierr); }
1954 jroman 229
      eps->nds = k;
1917 jroman 230
      eps->ds_ortho = PETSC_TRUE;
527 dsic.upv.es!antodo 231
    }
232
  }
233
  ierr = STCheckNullSpace(eps->OP,eps->nds,eps->DS);CHKERRQ(ierr);
1800 jroman 234
 
1932 jroman 235
  /* process initial vectors */
236
  if (eps->nini<0) {
237
    eps->nini = -eps->nini;
2219 jroman 238
    if (eps->nini>eps->ncv) SETERRQ(((PetscObject)eps)->comm,1,"The number of initial vectors is larger than ncv");
1932 jroman 239
    k = 0;
240
    for (i=0;i<eps->nini;i++) {
241
      ierr = VecCopy(eps->IS[i],eps->V[k]);CHKERRQ(ierr);
2305 jroman 242
      ierr = VecDestroy(&eps->IS[i]);CHKERRQ(ierr);
1932 jroman 243
      ierr = IPOrthogonalize(eps->ip,eps->nds,eps->DS,k,PETSC_NULL,eps->V,eps->V[k],PETSC_NULL,&norm,&lindep);CHKERRQ(ierr);
2499 jroman 244
      if (norm==0.0 || lindep) {
245
        ierr = PetscInfo(eps,"Linearly dependent initial vector found, removing...\n");CHKERRQ(ierr);
246
      } else {
1932 jroman 247
        ierr = VecScale(eps->V[k],1.0/norm);CHKERRQ(ierr);
248
        k++;
249
      }
250
    }
251
    eps->nini = k;
252
    ierr = PetscFree(eps->IS);CHKERRQ(ierr);
253
  }
1937 jroman 254
  if (eps->ninil<0) {
2499 jroman 255
    if (!eps->leftvecs) {
256
      ierr = PetscInfo(eps,"Ignoring initial left vectors\n");CHKERRQ(ierr);
257
    } else {
1937 jroman 258
      eps->ninil = -eps->ninil;
2219 jroman 259
      if (eps->ninil>eps->ncv) SETERRQ(((PetscObject)eps)->comm,1,"The number of initial left vectors is larger than ncv");
1937 jroman 260
      k = 0;
261
      for (i=0;i<eps->ninil;i++) {
262
        ierr = VecCopy(eps->ISL[i],eps->W[k]);CHKERRQ(ierr);
2305 jroman 263
        ierr = VecDestroy(&eps->ISL[i]);CHKERRQ(ierr);
1937 jroman 264
        ierr = IPOrthogonalize(eps->ip,0,PETSC_NULL,k,PETSC_NULL,eps->W,eps->W[k],PETSC_NULL,&norm,&lindep);CHKERRQ(ierr);
2499 jroman 265
        if (norm==0.0 || lindep) {
266
          ierr = PetscInfo(eps,"Linearly dependent initial left vector found, removing...\n");CHKERRQ(ierr);
267
        } else {
1937 jroman 268
          ierr = VecScale(eps->W[k],1.0/norm);CHKERRQ(ierr);
269
          k++;
270
        }
271
      }
272
      eps->ninil = k;
273
      ierr = PetscFree(eps->ISL);CHKERRQ(ierr);
274
    }
275
  }
1932 jroman 276
 
527 dsic.upv.es!antodo 277
  ierr = PetscLogEventEnd(EPS_SetUp,eps,0,0,0);CHKERRQ(ierr);
278
  eps->setupcalled = 1;
279
  PetscFunctionReturn(0);
280
}
281
 
282
#undef __FUNCT__  
283
#define __FUNCT__ "EPSSetOperators"
284
/*@
285
   EPSSetOperators - Sets the matrices associated with the eigenvalue problem.
286
 
287
   Collective on EPS and Mat
288
 
289
   Input Parameters:
290
+  eps - the eigenproblem solver context
291
.  A  - the matrix associated with the eigensystem
292
-  B  - the second matrix in the case of generalized eigenproblems
293
 
294
   Notes:
295
   To specify a standard eigenproblem, use PETSC_NULL for parameter B.
296
 
2348 jroman 297
   It must be called after EPSSetUp(). If it is called again after EPSSetUp() then
298
   the EPS object is reset.
299
 
527 dsic.upv.es!antodo 300
   Level: beginner
301
 
2348 jroman 302
.seealso: EPSSolve(), EPSSetUp(), EPSReset(), EPSGetST(), STGetOperators()
527 dsic.upv.es!antodo 303
@*/
304
PetscErrorCode EPSSetOperators(EPS eps,Mat A,Mat B)
305
{
306
  PetscErrorCode ierr;
1928 jroman 307
  PetscInt       m,n,m0;
527 dsic.upv.es!antodo 308
 
309
  PetscFunctionBegin;
2213 jroman 310
  PetscValidHeaderSpecific(eps,EPS_CLASSID,1);
311
  PetscValidHeaderSpecific(A,MAT_CLASSID,2);
312
  if (B) PetscValidHeaderSpecific(B,MAT_CLASSID,3);
1014 slepc 313
  PetscCheckSameComm(eps,1,A,2);
314
  if (B) PetscCheckSameComm(eps,1,B,3);
527 dsic.upv.es!antodo 315
 
316
  /* Check for square matrices */
317
  ierr = MatGetSize(A,&m,&n);CHKERRQ(ierr);
2219 jroman 318
  if (m!=n) SETERRQ(((PetscObject)eps)->comm,1,"A is a non-square matrix");
527 dsic.upv.es!antodo 319
  if (B) {
1928 jroman 320
    ierr = MatGetSize(B,&m0,&n);CHKERRQ(ierr);
2219 jroman 321
    if (m0!=n) SETERRQ(((PetscObject)eps)->comm,1,"B is a non-square matrix");
322
    if (m!=m0) SETERRQ(((PetscObject)eps)->comm,1,"Dimensions of A and B do not match");
527 dsic.upv.es!antodo 323
  }
324
 
2348 jroman 325
  if (eps->setupcalled) { ierr = EPSReset(eps);CHKERRQ(ierr); }
2371 jroman 326
  if (!eps->OP) { ierr = EPSGetST(eps,&eps->OP);CHKERRQ(ierr); }
527 dsic.upv.es!antodo 327
  ierr = STSetOperators(eps->OP,A,B);CHKERRQ(ierr);
328
  PetscFunctionReturn(0);
329
}
330
 
1516 slepc 331
#undef __FUNCT__
332
#define __FUNCT__ "EPSGetOperators"
333
/*@
334
   EPSGetOperators - Gets the matrices associated with the eigensystem.
335
 
336
   Collective on EPS and Mat
337
 
338
   Input Parameter:
339
.  eps - the EPS context
340
 
341
   Output Parameters:
342
+  A  - the matrix associated with the eigensystem
343
-  B  - the second matrix in the case of generalized eigenproblems
344
 
345
   Level: intermediate
346
 
347
.seealso: EPSSolve(), EPSGetST(), STGetOperators(), STSetOperators()
348
@*/
2331 jroman 349
PetscErrorCode EPSGetOperators(EPS eps,Mat *A,Mat *B)
1516 slepc 350
{
351
  PetscErrorCode ierr;
352
  ST             st;
353
 
354
  PetscFunctionBegin;
2213 jroman 355
  PetscValidHeaderSpecific(eps,EPS_CLASSID,1);
1516 slepc 356
  if (A) PetscValidPointer(A,2);
357
  if (B) PetscValidPointer(B,3);
358
  ierr = EPSGetST(eps,&st);CHKERRQ(ierr);
359
  ierr = STGetOperators(st,A,B);CHKERRQ(ierr);
360
  PetscFunctionReturn(0);
361
}
362
 
527 dsic.upv.es!antodo 363
#undef __FUNCT__  
1926 jroman 364
#define __FUNCT__ "EPSSetDeflationSpace"
527 dsic.upv.es!antodo 365
/*@
1926 jroman 366
   EPSSetDeflationSpace - Specify a basis of vectors that constitute
1917 jroman 367
   the deflation space.
527 dsic.upv.es!antodo 368
 
1811 jroman 369
   Collective on EPS and Vec
527 dsic.upv.es!antodo 370
 
371
   Input Parameter:
372
+  eps   - the eigenproblem solver context
1917 jroman 373
.  n     - number of vectors
374
-  ds    - set of basis vectors of the deflation space
527 dsic.upv.es!antodo 375
 
376
   Notes:
377
   When a deflation space is given, the eigensolver seeks the eigensolution
378
   in the restriction of the problem to the orthogonal complement of this
379
   space. This can be used for instance in the case that an invariant
380
   subspace is known beforehand (such as the nullspace of the matrix).
381
 
1926 jroman 382
   Basis vectors set by a previous call to EPSSetDeflationSpace() are
1917 jroman 383
   replaced.
527 dsic.upv.es!antodo 384
 
1917 jroman 385
   The vectors do not need to be mutually orthonormal, since they are explicitly
386
   orthonormalized internally.
527 dsic.upv.es!antodo 387
 
1932 jroman 388
   These vectors persist from one EPSSolve() call to the other, use
389
   EPSRemoveDeflationSpace() to eliminate them.
390
 
527 dsic.upv.es!antodo 391
   Level: intermediate
392
 
393
.seealso: EPSRemoveDeflationSpace()
394
@*/
1926 jroman 395
PetscErrorCode EPSSetDeflationSpace(EPS eps,PetscInt n,Vec *ds)
527 dsic.upv.es!antodo 396
{
397
  PetscErrorCode ierr;
1917 jroman 398
  PetscInt       i;
527 dsic.upv.es!antodo 399
 
400
  PetscFunctionBegin;
2213 jroman 401
  PetscValidHeaderSpecific(eps,EPS_CLASSID,1);
2326 jroman 402
  PetscValidLogicalCollectiveInt(eps,n,2);
2436 jroman 403
  if (n<0) SETERRQ(((PetscObject)eps)->comm,PETSC_ERR_ARG_OUTOFRANGE,"Argument n out of range");
1917 jroman 404
 
405
  /* free previous vectors */
406
  ierr = EPSRemoveDeflationSpace(eps);CHKERRQ(ierr);
407
 
408
  /* get references of passed vectors */
2436 jroman 409
  if (n>0) {
410
    ierr = PetscMalloc(n*sizeof(Vec),&eps->DS);CHKERRQ(ierr);
411
    for (i=0;i<n;i++) {
412
      ierr = PetscObjectReference((PetscObject)ds[i]);CHKERRQ(ierr);
413
      eps->DS[i] = ds[i];
414
    }
415
    eps->setupcalled = 0;
416
    eps->ds_ortho = PETSC_FALSE;
527 dsic.upv.es!antodo 417
  }
1917 jroman 418
 
419
  eps->nds = n;
527 dsic.upv.es!antodo 420
  PetscFunctionReturn(0);
421
}
422
 
423
#undef __FUNCT__  
424
#define __FUNCT__ "EPSRemoveDeflationSpace"
425
/*@
426
   EPSRemoveDeflationSpace - Removes the deflation space.
427
 
1811 jroman 428
   Collective on EPS
527 dsic.upv.es!antodo 429
 
430
   Input Parameter:
431
.  eps   - the eigenproblem solver context
432
 
433
   Level: intermediate
434
 
1926 jroman 435
.seealso: EPSSetDeflationSpace()
527 dsic.upv.es!antodo 436
@*/
437
PetscErrorCode EPSRemoveDeflationSpace(EPS eps)
438
{
439
  PetscErrorCode ierr;
440
 
441
  PetscFunctionBegin;
2213 jroman 442
  PetscValidHeaderSpecific(eps,EPS_CLASSID,1);
2410 jroman 443
  ierr = VecDestroyVecs(eps->nds,&eps->DS);CHKERRQ(ierr);
1917 jroman 444
  eps->nds = 0;
527 dsic.upv.es!antodo 445
  eps->setupcalled = 0;
1917 jroman 446
  eps->ds_ortho = PETSC_FALSE;
527 dsic.upv.es!antodo 447
  PetscFunctionReturn(0);
448
}
1932 jroman 449
 
450
#undef __FUNCT__  
451
#define __FUNCT__ "EPSSetInitialSpace"
452
/*@
453
   EPSSetInitialSpace - Specify a basis of vectors that constitute the initial
454
   space, that is, the subspace from which the solver starts to iterate.
455
 
456
   Collective on EPS and Vec
457
 
458
   Input Parameter:
459
+  eps   - the eigenproblem solver context
460
.  n     - number of vectors
461
-  is    - set of basis vectors of the initial space
462
 
463
   Notes:
464
   Some solvers start to iterate on a single vector (initial vector). In that case,
465
   the other vectors are ignored.
466
 
467
   In contrast to EPSSetDeflationSpace(), these vectors do not persist from one
468
   EPSSolve() call to the other, so the initial space should be set every time.
469
 
470
   The vectors do not need to be mutually orthonormal, since they are explicitly
471
   orthonormalized internally.
472
 
1937 jroman 473
   Common usage of this function is when the user can provide a rough approximation
474
   of the wanted eigenspace. Then, convergence may be faster.
475
 
1932 jroman 476
   Level: intermediate
477
 
1937 jroman 478
.seealso: EPSSetInitialSpaceLeft(), EPSSetDeflationSpace()
1932 jroman 479
@*/
480
PetscErrorCode EPSSetInitialSpace(EPS eps,PetscInt n,Vec *is)
481
{
482
  PetscErrorCode ierr;
483
  PetscInt       i;
484
 
485
  PetscFunctionBegin;
2213 jroman 486
  PetscValidHeaderSpecific(eps,EPS_CLASSID,1);
2326 jroman 487
  PetscValidLogicalCollectiveInt(eps,n,2);
2214 jroman 488
  if (n<0) SETERRQ(((PetscObject)eps)->comm,PETSC_ERR_ARG_OUTOFRANGE,"Argument n cannot be negative");
1932 jroman 489
 
490
  /* free previous non-processed vectors */
491
  if (eps->nini<0) {
492
    for (i=0;i<-eps->nini;i++) {
2305 jroman 493
      ierr = VecDestroy(&eps->IS[i]);CHKERRQ(ierr);
1932 jroman 494
    }
495
    ierr = PetscFree(eps->IS);CHKERRQ(ierr);
496
  }
497
 
498
  /* get references of passed vectors */
2436 jroman 499
  if (n>0) {
500
    ierr = PetscMalloc(n*sizeof(Vec),&eps->IS);CHKERRQ(ierr);
501
    for (i=0;i<n;i++) {
502
      ierr = PetscObjectReference((PetscObject)is[i]);CHKERRQ(ierr);
503
      eps->IS[i] = is[i];
504
    }
505
    eps->setupcalled = 0;
1932 jroman 506
  }
507
 
508
  eps->nini = -n;
509
  PetscFunctionReturn(0);
510
}
511
 
1937 jroman 512
#undef __FUNCT__  
513
#define __FUNCT__ "EPSSetInitialSpaceLeft"
514
/*@
515
   EPSSetInitialSpaceLeft - Specify a basis of vectors that constitute the initial
516
   left space, that is, the subspace from which the solver starts to iterate for
517
   building the left subspace (in methods that work with two subspaces).
1932 jroman 518
 
1937 jroman 519
   Collective on EPS and Vec
520
 
521
   Input Parameter:
522
+  eps   - the eigenproblem solver context
523
.  n     - number of vectors
524
-  is    - set of basis vectors of the initial left space
525
 
526
   Notes:
527
   Some solvers start to iterate on a single vector (initial left vector). In that case,
528
   the other vectors are ignored.
529
 
530
   In contrast to EPSSetDeflationSpace(), these vectors do not persist from one
531
   EPSSolve() call to the other, so the initial left space should be set every time.
532
 
533
   The vectors do not need to be mutually orthonormal, since they are explicitly
534
   orthonormalized internally.
535
 
536
   Common usage of this function is when the user can provide a rough approximation
537
   of the wanted left eigenspace. Then, convergence may be faster.
538
 
539
   Level: intermediate
540
 
541
.seealso: EPSSetInitialSpace(), EPSSetDeflationSpace()
542
@*/
543
PetscErrorCode EPSSetInitialSpaceLeft(EPS eps,PetscInt n,Vec *is)
544
{
545
  PetscErrorCode ierr;
546
  PetscInt       i;
547
 
548
  PetscFunctionBegin;
2213 jroman 549
  PetscValidHeaderSpecific(eps,EPS_CLASSID,1);
2326 jroman 550
  PetscValidLogicalCollectiveInt(eps,n,2);
2214 jroman 551
  if (n<0) SETERRQ(((PetscObject)eps)->comm,PETSC_ERR_ARG_OUTOFRANGE,"Argument n cannot be negative");
1937 jroman 552
 
553
  /* free previous non-processed vectors */
554
  if (eps->ninil<0) {
555
    for (i=0;i<-eps->ninil;i++) {
2305 jroman 556
      ierr = VecDestroy(&eps->ISL[i]);CHKERRQ(ierr);
1937 jroman 557
    }
558
    ierr = PetscFree(eps->ISL);CHKERRQ(ierr);
559
  }
560
 
561
  /* get references of passed vectors */
2436 jroman 562
  if (n>0) {
563
    ierr = PetscMalloc(n*sizeof(Vec),&eps->ISL);CHKERRQ(ierr);
564
    for (i=0;i<n;i++) {
565
      ierr = PetscObjectReference((PetscObject)is[i]);CHKERRQ(ierr);
566
      eps->ISL[i] = is[i];
567
    }
568
    eps->setupcalled = 0;
1937 jroman 569
  }
570
 
571
  eps->ninil = -n;
572
  PetscFunctionReturn(0);
573
}
574