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