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