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