| 6 |
dsic.upv.es!jroman |
1 |
/*
|
|
|
2 |
The ST (spectral transformation) interface routines, callable by users.
|
| 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 |
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
| 6 |
dsic.upv.es!jroman |
22 |
*/
|
|
|
23 |
|
| 2283 |
jroman |
24 |
#include <private/stimpl.h> /*I "slepcst.h" I*/
|
| 6 |
dsic.upv.es!jroman |
25 |
|
| 2213 |
jroman |
26 |
PetscClassId ST_CLASSID = 0;
|
| 1493 |
slepc |
27 |
PetscLogEvent ST_SetUp = 0, ST_Apply = 0, ST_ApplyTranspose = 0;
|
| 2216 |
jroman |
28 |
static PetscBool STPackageInitialized = PETSC_FALSE;
|
| 842 |
dsic.upv.es!antodo |
29 |
|
| 6 |
dsic.upv.es!jroman |
30 |
#undef __FUNCT__
|
| 1851 |
antodo |
31 |
#define __FUNCT__ "STFinalizePackage"
|
|
|
32 |
/*@C
|
| 1853 |
antodo |
33 |
STFinalizePackage - This function destroys everything in the Slepc interface to the ST package. It is
|
|
|
34 |
called from SlepcFinalize().
|
| 1851 |
antodo |
35 |
|
|
|
36 |
Level: developer
|
|
|
37 |
|
| 1853 |
antodo |
38 |
.seealso: SlepcFinalize()
|
| 1851 |
antodo |
39 |
@*/
|
|
|
40 |
PetscErrorCode STFinalizePackage(void)
|
|
|
41 |
{
|
|
|
42 |
PetscFunctionBegin;
|
|
|
43 |
STPackageInitialized = PETSC_FALSE;
|
|
|
44 |
STList = 0;
|
|
|
45 |
PetscFunctionReturn(0);
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
#undef __FUNCT__
|
| 842 |
dsic.upv.es!antodo |
49 |
#define __FUNCT__ "STInitializePackage"
|
|
|
50 |
/*@C
|
|
|
51 |
STInitializePackage - This function initializes everything in the ST package. It is called
|
|
|
52 |
from PetscDLLibraryRegister() when using dynamic libraries, and on the first call to STCreate()
|
|
|
53 |
when using static libraries.
|
|
|
54 |
|
|
|
55 |
Input Parameter:
|
|
|
56 |
path - The dynamic library path, or PETSC_NULL
|
|
|
57 |
|
|
|
58 |
Level: developer
|
|
|
59 |
|
|
|
60 |
.seealso: SlepcInitialize()
|
|
|
61 |
@*/
|
| 2212 |
jroman |
62 |
PetscErrorCode STInitializePackage(const char *path) {
|
| 2216 |
jroman |
63 |
char logList[256];
|
|
|
64 |
char *className;
|
|
|
65 |
PetscBool opt;
|
| 842 |
dsic.upv.es!antodo |
66 |
PetscErrorCode ierr;
|
|
|
67 |
|
|
|
68 |
PetscFunctionBegin;
|
| 1851 |
antodo |
69 |
if (STPackageInitialized) PetscFunctionReturn(0);
|
|
|
70 |
STPackageInitialized = PETSC_TRUE;
|
| 842 |
dsic.upv.es!antodo |
71 |
/* Register Classes */
|
| 2213 |
jroman |
72 |
ierr = PetscClassIdRegister("Spectral Transform",&ST_CLASSID);CHKERRQ(ierr);
|
| 842 |
dsic.upv.es!antodo |
73 |
/* Register Constructors */
|
|
|
74 |
ierr = STRegisterAll(path);CHKERRQ(ierr);
|
|
|
75 |
/* Register Events */
|
| 2213 |
jroman |
76 |
ierr = PetscLogEventRegister("STSetUp",ST_CLASSID,&ST_SetUp);CHKERRQ(ierr);
|
|
|
77 |
ierr = PetscLogEventRegister("STApply",ST_CLASSID,&ST_Apply);CHKERRQ(ierr);
|
|
|
78 |
ierr = PetscLogEventRegister("STApplyTranspose",ST_CLASSID,&ST_ApplyTranspose); CHKERRQ(ierr);
|
| 842 |
dsic.upv.es!antodo |
79 |
/* Process info exclusions */
|
| 2213 |
jroman |
80 |
ierr = PetscOptionsGetString(PETSC_NULL, "-info_exclude", logList, 256, &opt);CHKERRQ(ierr);
|
| 842 |
dsic.upv.es!antodo |
81 |
if (opt) {
|
|
|
82 |
ierr = PetscStrstr(logList, "st", &className);CHKERRQ(ierr);
|
|
|
83 |
if (className) {
|
| 2213 |
jroman |
84 |
ierr = PetscInfoDeactivateClass(ST_CLASSID);CHKERRQ(ierr);
|
| 842 |
dsic.upv.es!antodo |
85 |
}
|
|
|
86 |
}
|
|
|
87 |
/* Process summary exclusions */
|
|
|
88 |
ierr = PetscOptionsGetString(PETSC_NULL, "-log_summary_exclude", logList, 256, &opt);CHKERRQ(ierr);
|
|
|
89 |
if (opt) {
|
|
|
90 |
ierr = PetscStrstr(logList, "st", &className);CHKERRQ(ierr);
|
|
|
91 |
if (className) {
|
| 2213 |
jroman |
92 |
ierr = PetscLogEventDeactivateClass(ST_CLASSID);CHKERRQ(ierr);
|
| 842 |
dsic.upv.es!antodo |
93 |
}
|
|
|
94 |
}
|
| 1851 |
antodo |
95 |
ierr = PetscRegisterFinalize(STFinalizePackage);CHKERRQ(ierr);
|
| 842 |
dsic.upv.es!antodo |
96 |
PetscFunctionReturn(0);
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
#undef __FUNCT__
|
| 6 |
dsic.upv.es!jroman |
100 |
#define __FUNCT__ "STDestroy"
|
| 1345 |
slepc |
101 |
/*@
|
| 6 |
dsic.upv.es!jroman |
102 |
STDestroy - Destroys ST context that was created with STCreate().
|
|
|
103 |
|
|
|
104 |
Collective on ST
|
|
|
105 |
|
|
|
106 |
Input Parameter:
|
|
|
107 |
. st - the spectral transformation context
|
|
|
108 |
|
|
|
109 |
Level: beginner
|
|
|
110 |
|
|
|
111 |
.seealso: STCreate(), STSetUp()
|
|
|
112 |
@*/
|
| 476 |
dsic.upv.es!antodo |
113 |
PetscErrorCode STDestroy(ST st)
|
| 6 |
dsic.upv.es!jroman |
114 |
{
|
| 476 |
dsic.upv.es!antodo |
115 |
PetscErrorCode ierr;
|
| 6 |
dsic.upv.es!jroman |
116 |
|
|
|
117 |
PetscFunctionBegin;
|
| 2213 |
jroman |
118 |
PetscValidHeaderSpecific(st,ST_CLASSID,1);
|
| 1422 |
slepc |
119 |
if (--((PetscObject)st)->refct > 0) PetscFunctionReturn(0);
|
| 6 |
dsic.upv.es!jroman |
120 |
|
|
|
121 |
/* if memory was published with AMS then destroy it */
|
|
|
122 |
ierr = PetscObjectDepublish(st);CHKERRQ(ierr);
|
|
|
123 |
|
|
|
124 |
if (st->ops->destroy) { ierr = (*st->ops->destroy)(st);CHKERRQ(ierr); }
|
| 1563 |
slepc |
125 |
if (st->A) { ierr = MatDestroy(st->A);CHKERRQ(ierr); }
|
|
|
126 |
if (st->B) { ierr = MatDestroy(st->B);CHKERRQ(ierr); }
|
| 18 |
dsic.upv.es!jroman |
127 |
if (st->ksp) { ierr = KSPDestroy(st->ksp);CHKERRQ(ierr); }
|
| 344 |
dsic.upv.es!antodo |
128 |
if (st->w) { ierr = VecDestroy(st->w);CHKERRQ(ierr); }
|
| 1804 |
jroman |
129 |
if (st->D) { ierr = VecDestroy(st->D);CHKERRQ(ierr); }
|
|
|
130 |
if (st->wb){ ierr = VecDestroy(st->wb);CHKERRQ(ierr); }
|
| 1940 |
jroman |
131 |
if (st->shift_matrix != ST_MATMODE_INPLACE && st->mat) {
|
| 344 |
dsic.upv.es!antodo |
132 |
ierr = MatDestroy(st->mat);CHKERRQ(ierr);
|
|
|
133 |
}
|
| 6 |
dsic.upv.es!jroman |
134 |
|
| 1570 |
slepc |
135 |
ierr = PetscHeaderDestroy(st);CHKERRQ(ierr);
|
| 6 |
dsic.upv.es!jroman |
136 |
PetscFunctionReturn(0);
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
#undef __FUNCT__
|
|
|
140 |
#define __FUNCT__ "STCreate"
|
|
|
141 |
/*@C
|
|
|
142 |
STCreate - Creates a spectral transformation context.
|
|
|
143 |
|
|
|
144 |
Collective on MPI_Comm
|
|
|
145 |
|
|
|
146 |
Input Parameter:
|
|
|
147 |
. comm - MPI communicator
|
|
|
148 |
|
|
|
149 |
Output Parameter:
|
|
|
150 |
. st - location to put the spectral transformation context
|
|
|
151 |
|
|
|
152 |
Level: beginner
|
|
|
153 |
|
| 1364 |
slepc |
154 |
.seealso: STSetUp(), STApply(), STDestroy(), ST
|
| 6 |
dsic.upv.es!jroman |
155 |
@*/
|
| 476 |
dsic.upv.es!antodo |
156 |
PetscErrorCode STCreate(MPI_Comm comm,ST *newst)
|
| 6 |
dsic.upv.es!jroman |
157 |
{
|
| 476 |
dsic.upv.es!antodo |
158 |
PetscErrorCode ierr;
|
|
|
159 |
ST st;
|
| 812 |
dsic.upv.es!antodo |
160 |
const char *prefix;
|
| 6 |
dsic.upv.es!jroman |
161 |
|
|
|
162 |
PetscFunctionBegin;
|
| 476 |
dsic.upv.es!antodo |
163 |
PetscValidPointer(newst,2);
|
| 6 |
dsic.upv.es!jroman |
164 |
*newst = 0;
|
|
|
165 |
|
| 2213 |
jroman |
166 |
ierr = PetscHeaderCreate(st,_p_ST,struct _STOps,ST_CLASSID,-1,"ST",comm,STDestroy,STView);CHKERRQ(ierr);
|
| 337 |
dsic.upv.es!antodo |
167 |
ierr = PetscMemzero(st->ops,sizeof(struct _STOps));CHKERRQ(ierr);
|
| 6 |
dsic.upv.es!jroman |
168 |
|
|
|
169 |
st->A = 0;
|
|
|
170 |
st->B = 0;
|
| 110 |
dsic.upv.es!antodo |
171 |
st->sigma = 0.0;
|
| 2074 |
jroman |
172 |
st->sigma_set = PETSC_FALSE;
|
|
|
173 |
st->defsigma = 0.0;
|
| 6 |
dsic.upv.es!jroman |
174 |
st->data = 0;
|
|
|
175 |
st->setupcalled = 0;
|
| 344 |
dsic.upv.es!antodo |
176 |
st->w = 0;
|
| 1804 |
jroman |
177 |
st->D = 0;
|
|
|
178 |
st->wb = 0;
|
| 1940 |
jroman |
179 |
st->shift_matrix = ST_MATMODE_COPY;
|
| 344 |
dsic.upv.es!antodo |
180 |
st->str = DIFFERENT_NONZERO_PATTERN;
|
| 246 |
dsic.upv.es!antodo |
181 |
|
| 1422 |
slepc |
182 |
ierr = KSPCreate(((PetscObject)st)->comm,&st->ksp);CHKERRQ(ierr);
|
| 246 |
dsic.upv.es!antodo |
183 |
ierr = STGetOptionsPrefix(st,&prefix);CHKERRQ(ierr);
|
|
|
184 |
ierr = KSPSetOptionsPrefix(st->ksp,prefix);CHKERRQ(ierr);
|
|
|
185 |
ierr = KSPAppendOptionsPrefix(st->ksp,"st_");CHKERRQ(ierr);
|
| 1568 |
slepc |
186 |
ierr = PetscObjectIncrementTabLevel((PetscObject)st->ksp,(PetscObject)st,1);CHKERRQ(ierr);
|
| 246 |
dsic.upv.es!antodo |
187 |
|
| 6 |
dsic.upv.es!jroman |
188 |
*newst = st;
|
|
|
189 |
PetscFunctionReturn(0);
|
|
|
190 |
|
|
|
191 |
}
|
|
|
192 |
|
|
|
193 |
#undef __FUNCT__
|
|
|
194 |
#define __FUNCT__ "STSetOperators"
|
|
|
195 |
/*@
|
|
|
196 |
STSetOperators - Sets the matrices associated with the eigenvalue problem.
|
|
|
197 |
|
|
|
198 |
Collective on ST and Mat
|
|
|
199 |
|
|
|
200 |
Input Parameters:
|
|
|
201 |
+ st - the spectral transformation context
|
|
|
202 |
. A - the matrix associated with the eigensystem
|
|
|
203 |
- B - the second matrix in the case of generalized eigenproblems
|
|
|
204 |
|
|
|
205 |
Notes:
|
|
|
206 |
To specify a standard eigenproblem, use PETSC_NULL for B.
|
|
|
207 |
|
|
|
208 |
Level: intermediate
|
|
|
209 |
|
|
|
210 |
.seealso: STGetOperators()
|
|
|
211 |
@*/
|
| 476 |
dsic.upv.es!antodo |
212 |
PetscErrorCode STSetOperators(ST st,Mat A,Mat B)
|
| 6 |
dsic.upv.es!jroman |
213 |
{
|
| 1563 |
slepc |
214 |
PetscErrorCode ierr;
|
| 6 |
dsic.upv.es!jroman |
215 |
PetscFunctionBegin;
|
| 2213 |
jroman |
216 |
PetscValidHeaderSpecific(st,ST_CLASSID,1);
|
|
|
217 |
PetscValidHeaderSpecific(A,MAT_CLASSID,2);
|
|
|
218 |
if (B) PetscValidHeaderSpecific(B,MAT_CLASSID,3);
|
| 1014 |
slepc |
219 |
PetscCheckSameComm(st,1,A,2);
|
|
|
220 |
if (B) PetscCheckSameComm(st,1,B,3);
|
| 1563 |
slepc |
221 |
ierr = PetscObjectReference((PetscObject)A);CHKERRQ(ierr);
|
|
|
222 |
if (st->A) { ierr = MatDestroy(st->A);CHKERRQ(ierr); }
|
| 6 |
dsic.upv.es!jroman |
223 |
st->A = A;
|
| 1563 |
slepc |
224 |
if (B) { ierr = PetscObjectReference((PetscObject)B);CHKERRQ(ierr); }
|
|
|
225 |
if (st->B) { ierr = MatDestroy(st->B);CHKERRQ(ierr); }
|
| 6 |
dsic.upv.es!jroman |
226 |
st->B = B;
|
|
|
227 |
st->setupcalled = 0;
|
|
|
228 |
PetscFunctionReturn(0);
|
|
|
229 |
}
|
|
|
230 |
|
|
|
231 |
#undef __FUNCT__
|
|
|
232 |
#define __FUNCT__ "STGetOperators"
|
|
|
233 |
/*@C
|
|
|
234 |
STGetOperators - Gets the matrices associated with the eigensystem.
|
|
|
235 |
|
|
|
236 |
Not collective, though parallel Mats are returned if the ST is parallel
|
|
|
237 |
|
|
|
238 |
Input Parameter:
|
|
|
239 |
. st - the spectral transformation context
|
|
|
240 |
|
|
|
241 |
Output Parameters:
|
|
|
242 |
. A - the matrix associated with the eigensystem
|
|
|
243 |
- B - the second matrix in the case of generalized eigenproblems
|
|
|
244 |
|
|
|
245 |
Level: intermediate
|
|
|
246 |
|
|
|
247 |
.seealso: STSetOperators()
|
|
|
248 |
@*/
|
| 476 |
dsic.upv.es!antodo |
249 |
PetscErrorCode STGetOperators(ST st,Mat *A,Mat *B)
|
| 6 |
dsic.upv.es!jroman |
250 |
{
|
|
|
251 |
PetscFunctionBegin;
|
| 2213 |
jroman |
252 |
PetscValidHeaderSpecific(st,ST_CLASSID,1);
|
| 6 |
dsic.upv.es!jroman |
253 |
if (A) *A = st->A;
|
|
|
254 |
if (B) *B = st->B;
|
|
|
255 |
PetscFunctionReturn(0);
|
|
|
256 |
}
|
|
|
257 |
|
|
|
258 |
#undef __FUNCT__
|
|
|
259 |
#define __FUNCT__ "STSetShift"
|
|
|
260 |
/*@
|
| 1804 |
jroman |
261 |
STSetShift - Sets the shift associated with the spectral transformation.
|
| 6 |
dsic.upv.es!jroman |
262 |
|
| 1804 |
jroman |
263 |
Collective on ST
|
| 6 |
dsic.upv.es!jroman |
264 |
|
|
|
265 |
Input Parameters:
|
|
|
266 |
+ st - the spectral transformation context
|
|
|
267 |
- shift - the value of the shift
|
|
|
268 |
|
|
|
269 |
Note:
|
|
|
270 |
In some spectral transformations, changing the shift may have associated
|
|
|
271 |
a lot of work, for example recomputing a factorization.
|
|
|
272 |
|
|
|
273 |
Level: beginner
|
|
|
274 |
|
|
|
275 |
@*/
|
| 476 |
dsic.upv.es!antodo |
276 |
PetscErrorCode STSetShift(ST st,PetscScalar shift)
|
| 6 |
dsic.upv.es!jroman |
277 |
{
|
| 476 |
dsic.upv.es!antodo |
278 |
PetscErrorCode ierr;
|
| 6 |
dsic.upv.es!jroman |
279 |
|
|
|
280 |
PetscFunctionBegin;
|
| 2213 |
jroman |
281 |
PetscValidHeaderSpecific(st,ST_CLASSID,1);
|
| 6 |
dsic.upv.es!jroman |
282 |
if (st->sigma != shift) {
|
|
|
283 |
if (st->ops->setshift) {
|
|
|
284 |
ierr = (*st->ops->setshift)(st,shift); CHKERRQ(ierr);
|
|
|
285 |
}
|
|
|
286 |
}
|
|
|
287 |
st->sigma = shift;
|
| 2074 |
jroman |
288 |
st->sigma_set = PETSC_TRUE;
|
| 6 |
dsic.upv.es!jroman |
289 |
PetscFunctionReturn(0);
|
|
|
290 |
}
|
|
|
291 |
|
|
|
292 |
#undef __FUNCT__
|
|
|
293 |
#define __FUNCT__ "STGetShift"
|
|
|
294 |
/*@
|
|
|
295 |
STGetShift - Gets the shift associated with the spectral transformation.
|
|
|
296 |
|
|
|
297 |
Not collective
|
|
|
298 |
|
|
|
299 |
Input Parameter:
|
|
|
300 |
. st - the spectral transformation context
|
|
|
301 |
|
|
|
302 |
Output Parameter:
|
|
|
303 |
. shift - the value of the shift
|
|
|
304 |
|
|
|
305 |
Level: beginner
|
|
|
306 |
|
|
|
307 |
@*/
|
| 476 |
dsic.upv.es!antodo |
308 |
PetscErrorCode STGetShift(ST st,PetscScalar* shift)
|
| 6 |
dsic.upv.es!jroman |
309 |
{
|
|
|
310 |
PetscFunctionBegin;
|
| 2213 |
jroman |
311 |
PetscValidHeaderSpecific(st,ST_CLASSID,1);
|
| 6 |
dsic.upv.es!jroman |
312 |
if (shift) *shift = st->sigma;
|
|
|
313 |
PetscFunctionReturn(0);
|
|
|
314 |
}
|
|
|
315 |
|
|
|
316 |
#undef __FUNCT__
|
| 2074 |
jroman |
317 |
#define __FUNCT__ "STSetDefaultShift"
|
|
|
318 |
/*@
|
|
|
319 |
STSetDefaultShift - Sets the value of the shift that should be employed if
|
|
|
320 |
the user did not specify one.
|
|
|
321 |
|
|
|
322 |
Collective on ST
|
|
|
323 |
|
|
|
324 |
Input Parameters:
|
|
|
325 |
+ st - the spectral transformation context
|
|
|
326 |
- defaultshift - the default value of the shift
|
|
|
327 |
|
|
|
328 |
Level: developer
|
|
|
329 |
|
|
|
330 |
@*/
|
|
|
331 |
PetscErrorCode STSetDefaultShift(ST st,PetscScalar defaultshift)
|
|
|
332 |
{
|
|
|
333 |
PetscFunctionBegin;
|
| 2213 |
jroman |
334 |
PetscValidHeaderSpecific(st,ST_CLASSID,1);
|
| 2074 |
jroman |
335 |
st->defsigma = defaultshift;
|
|
|
336 |
PetscFunctionReturn(0);
|
|
|
337 |
}
|
|
|
338 |
|
|
|
339 |
#undef __FUNCT__
|
| 1804 |
jroman |
340 |
#define __FUNCT__ "STSetBalanceMatrix"
|
|
|
341 |
/*@
|
|
|
342 |
STSetBalanceMatrix - Sets the diagonal matrix to be used for balancing.
|
|
|
343 |
|
|
|
344 |
Collective on ST and Vec
|
|
|
345 |
|
|
|
346 |
Input Parameters:
|
|
|
347 |
+ st - the spectral transformation context
|
|
|
348 |
- D - the diagonal matrix (represented as a vector)
|
|
|
349 |
|
|
|
350 |
Notes:
|
|
|
351 |
If this matrix is set, STApply will effectively apply D*OP*D^{-1}.
|
|
|
352 |
|
|
|
353 |
Balancing is usually set via EPSSetBalance, but the advanced user may use
|
|
|
354 |
this function to bypass the usual balancing methods.
|
|
|
355 |
|
|
|
356 |
Level: developer
|
|
|
357 |
|
|
|
358 |
.seealso: EPSSetBalance(), STApply(), STGetBalanceMatrix()
|
|
|
359 |
@*/
|
|
|
360 |
PetscErrorCode STSetBalanceMatrix(ST st,Vec D)
|
|
|
361 |
{
|
|
|
362 |
PetscErrorCode ierr;
|
|
|
363 |
|
|
|
364 |
PetscFunctionBegin;
|
| 2213 |
jroman |
365 |
PetscValidHeaderSpecific(st,ST_CLASSID,1);
|
|
|
366 |
PetscValidHeaderSpecific(D,VEC_CLASSID,2);
|
| 1804 |
jroman |
367 |
PetscCheckSameComm(st,1,D,2);
|
|
|
368 |
ierr = PetscObjectReference((PetscObject)D);CHKERRQ(ierr);
|
|
|
369 |
if (st->D) {
|
|
|
370 |
ierr = VecDestroy(st->D); CHKERRQ(ierr);
|
|
|
371 |
}
|
|
|
372 |
st->D = D;
|
|
|
373 |
if (!st->wb) {
|
|
|
374 |
ierr = VecDuplicate(st->D,&st->wb); CHKERRQ(ierr);
|
|
|
375 |
}
|
|
|
376 |
PetscFunctionReturn(0);
|
|
|
377 |
}
|
|
|
378 |
|
|
|
379 |
#undef __FUNCT__
|
|
|
380 |
#define __FUNCT__ "STGetBalanceMatrix"
|
|
|
381 |
/*@
|
|
|
382 |
STGetBalanceMatrix - Gets the balance matrix used by the spectral transformation.
|
|
|
383 |
|
|
|
384 |
Not collective, but vector is shared by all processors that share the ST
|
|
|
385 |
|
|
|
386 |
Input Parameter:
|
|
|
387 |
. st - the spectral transformation context
|
|
|
388 |
|
|
|
389 |
Output Parameter:
|
|
|
390 |
. D - the diagonal matrix (represented as a vector)
|
|
|
391 |
|
|
|
392 |
Note:
|
|
|
393 |
If the matrix was not set, a null pointer will be returned.
|
|
|
394 |
|
|
|
395 |
Level: developer
|
|
|
396 |
|
|
|
397 |
.seealso: STSetBalanceMatrix()
|
|
|
398 |
@*/
|
|
|
399 |
PetscErrorCode STGetBalanceMatrix(ST st,Vec *D)
|
|
|
400 |
{
|
|
|
401 |
PetscFunctionBegin;
|
| 2213 |
jroman |
402 |
PetscValidHeaderSpecific(st,ST_CLASSID,1);
|
| 1804 |
jroman |
403 |
PetscValidPointer(D,2);
|
|
|
404 |
*D = st->D;
|
|
|
405 |
PetscFunctionReturn(0);
|
|
|
406 |
}
|
|
|
407 |
|
|
|
408 |
#undef __FUNCT__
|
| 6 |
dsic.upv.es!jroman |
409 |
#define __FUNCT__ "STSetOptionsPrefix"
|
|
|
410 |
/*@C
|
|
|
411 |
STSetOptionsPrefix - Sets the prefix used for searching for all
|
|
|
412 |
ST options in the database.
|
|
|
413 |
|
|
|
414 |
Collective on ST
|
|
|
415 |
|
|
|
416 |
Input Parameters:
|
|
|
417 |
+ st - the spectral transformation context
|
|
|
418 |
- prefix - the prefix string to prepend to all ST option requests
|
|
|
419 |
|
|
|
420 |
Notes:
|
|
|
421 |
A hyphen (-) must NOT be given at the beginning of the prefix name.
|
|
|
422 |
The first character of all runtime options is AUTOMATICALLY the
|
|
|
423 |
hyphen.
|
|
|
424 |
|
|
|
425 |
Level: advanced
|
|
|
426 |
|
|
|
427 |
.seealso: STAppendOptionsPrefix(), STGetOptionsPrefix()
|
|
|
428 |
@*/
|
| 1248 |
slepc |
429 |
PetscErrorCode STSetOptionsPrefix(ST st,const char *prefix)
|
| 6 |
dsic.upv.es!jroman |
430 |
{
|
| 476 |
dsic.upv.es!antodo |
431 |
PetscErrorCode ierr;
|
| 6 |
dsic.upv.es!jroman |
432 |
|
|
|
433 |
PetscFunctionBegin;
|
| 2213 |
jroman |
434 |
PetscValidHeaderSpecific(st,ST_CLASSID,1);
|
| 1248 |
slepc |
435 |
ierr = PetscObjectSetOptionsPrefix((PetscObject)st,prefix);CHKERRQ(ierr);
|
|
|
436 |
ierr = KSPSetOptionsPrefix(st->ksp,prefix);CHKERRQ(ierr);
|
|
|
437 |
ierr = KSPAppendOptionsPrefix(st->ksp,"st_");CHKERRQ(ierr);
|
| 6 |
dsic.upv.es!jroman |
438 |
PetscFunctionReturn(0);
|
|
|
439 |
}
|
|
|
440 |
|
|
|
441 |
#undef __FUNCT__
|
|
|
442 |
#define __FUNCT__ "STAppendOptionsPrefix"
|
|
|
443 |
/*@C
|
|
|
444 |
STAppendOptionsPrefix - Appends to the prefix used for searching for all
|
|
|
445 |
ST options in the database.
|
|
|
446 |
|
|
|
447 |
Collective on ST
|
|
|
448 |
|
|
|
449 |
Input Parameters:
|
|
|
450 |
+ st - the spectral transformation context
|
|
|
451 |
- prefix - the prefix string to prepend to all ST option requests
|
|
|
452 |
|
|
|
453 |
Notes:
|
|
|
454 |
A hyphen (-) must NOT be given at the beginning of the prefix name.
|
|
|
455 |
The first character of all runtime options is AUTOMATICALLY the
|
|
|
456 |
hyphen.
|
|
|
457 |
|
|
|
458 |
Level: advanced
|
|
|
459 |
|
|
|
460 |
.seealso: STSetOptionsPrefix(), STGetOptionsPrefix()
|
|
|
461 |
@*/
|
| 1248 |
slepc |
462 |
PetscErrorCode STAppendOptionsPrefix(ST st,const char *prefix)
|
| 6 |
dsic.upv.es!jroman |
463 |
{
|
| 476 |
dsic.upv.es!antodo |
464 |
PetscErrorCode ierr;
|
| 6 |
dsic.upv.es!jroman |
465 |
|
|
|
466 |
PetscFunctionBegin;
|
| 2213 |
jroman |
467 |
PetscValidHeaderSpecific(st,ST_CLASSID,1);
|
| 1248 |
slepc |
468 |
ierr = PetscObjectAppendOptionsPrefix((PetscObject)st,prefix);CHKERRQ(ierr);
|
| 1422 |
slepc |
469 |
ierr = KSPSetOptionsPrefix(st->ksp,((PetscObject)st)->prefix);CHKERRQ(ierr);
|
| 1248 |
slepc |
470 |
ierr = KSPAppendOptionsPrefix(st->ksp,"st_");CHKERRQ(ierr);
|
| 6 |
dsic.upv.es!jroman |
471 |
PetscFunctionReturn(0);
|
|
|
472 |
}
|
|
|
473 |
|
|
|
474 |
#undef __FUNCT__
|
|
|
475 |
#define __FUNCT__ "STGetOptionsPrefix"
|
|
|
476 |
/*@C
|
|
|
477 |
STGetOptionsPrefix - Gets the prefix used for searching for all
|
|
|
478 |
ST options in the database.
|
|
|
479 |
|
|
|
480 |
Not Collective
|
|
|
481 |
|
|
|
482 |
Input Parameters:
|
|
|
483 |
. st - the spectral transformation context
|
|
|
484 |
|
|
|
485 |
Output Parameters:
|
|
|
486 |
. prefix - pointer to the prefix string used, is returned
|
|
|
487 |
|
|
|
488 |
Notes: On the Fortran side, the user should pass in a string 'prefix' of
|
|
|
489 |
sufficient length to hold the prefix.
|
|
|
490 |
|
|
|
491 |
Level: advanced
|
|
|
492 |
|
|
|
493 |
.seealso: STSetOptionsPrefix(), STAppendOptionsPrefix()
|
|
|
494 |
@*/
|
| 812 |
dsic.upv.es!antodo |
495 |
PetscErrorCode STGetOptionsPrefix(ST st,const char *prefix[])
|
| 6 |
dsic.upv.es!jroman |
496 |
{
|
| 476 |
dsic.upv.es!antodo |
497 |
PetscErrorCode ierr;
|
| 6 |
dsic.upv.es!jroman |
498 |
|
|
|
499 |
PetscFunctionBegin;
|
| 2213 |
jroman |
500 |
PetscValidHeaderSpecific(st,ST_CLASSID,1);
|
| 6 |
dsic.upv.es!jroman |
501 |
ierr = PetscObjectGetOptionsPrefix((PetscObject)st, prefix);CHKERRQ(ierr);
|
|
|
502 |
PetscFunctionReturn(0);
|
|
|
503 |
}
|
|
|
504 |
|
|
|
505 |
#undef __FUNCT__
|
|
|
506 |
#define __FUNCT__ "STView"
|
|
|
507 |
/*@C
|
|
|
508 |
STView - Prints the ST data structure.
|
|
|
509 |
|
|
|
510 |
Collective on ST
|
|
|
511 |
|
|
|
512 |
Input Parameters:
|
|
|
513 |
+ ST - the ST context
|
|
|
514 |
- viewer - optional visualization context
|
|
|
515 |
|
|
|
516 |
Note:
|
|
|
517 |
The available visualization contexts include
|
|
|
518 |
+ PETSC_VIEWER_STDOUT_SELF - standard output (default)
|
|
|
519 |
- PETSC_VIEWER_STDOUT_WORLD - synchronized standard
|
|
|
520 |
output where only the first processor opens
|
|
|
521 |
the file. All other processors send their
|
|
|
522 |
data to the first processor to print.
|
|
|
523 |
|
|
|
524 |
The user can open an alternative visualization contexts with
|
|
|
525 |
PetscViewerASCIIOpen() (output to a specified file).
|
|
|
526 |
|
|
|
527 |
Level: beginner
|
|
|
528 |
|
|
|
529 |
.seealso: EPSView(), PetscViewerASCIIOpen()
|
|
|
530 |
@*/
|
| 476 |
dsic.upv.es!antodo |
531 |
PetscErrorCode STView(ST st,PetscViewer viewer)
|
| 6 |
dsic.upv.es!jroman |
532 |
{
|
| 476 |
dsic.upv.es!antodo |
533 |
PetscErrorCode ierr;
|
| 1502 |
slepc |
534 |
const STType cstr;
|
| 1004 |
slepc |
535 |
const char* str;
|
| 2216 |
jroman |
536 |
PetscBool isascii,isstring;
|
| 6 |
dsic.upv.es!jroman |
537 |
PetscViewerFormat format;
|
|
|
538 |
|
|
|
539 |
PetscFunctionBegin;
|
| 2213 |
jroman |
540 |
PetscValidHeaderSpecific(st,ST_CLASSID,1);
|
| 1422 |
slepc |
541 |
if (!viewer) viewer = PETSC_VIEWER_STDOUT_(((PetscObject)st)->comm);
|
| 2213 |
jroman |
542 |
PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,2);
|
| 25 |
dsic.upv.es!jroman |
543 |
PetscCheckSameComm(st,1,viewer,2);
|
| 6 |
dsic.upv.es!jroman |
544 |
|
| 2215 |
jroman |
545 |
ierr = PetscTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&isascii);CHKERRQ(ierr);
|
|
|
546 |
ierr = PetscTypeCompare((PetscObject)viewer,PETSCVIEWERSTRING,&isstring);CHKERRQ(ierr);
|
| 6 |
dsic.upv.es!jroman |
547 |
if (isascii) {
|
|
|
548 |
ierr = PetscViewerGetFormat(viewer,&format);CHKERRQ(ierr);
|
| 2224 |
jroman |
549 |
ierr = PetscObjectPrintClassNamePrefixType((PetscObject)st,viewer,"ST Object");CHKERRQ(ierr);
|
| 6 |
dsic.upv.es!jroman |
550 |
#if !defined(PETSC_USE_COMPLEX)
|
| 358 |
dsic.upv.es!antodo |
551 |
ierr = PetscViewerASCIIPrintf(viewer," shift: %g\n",st->sigma);CHKERRQ(ierr);
|
| 6 |
dsic.upv.es!jroman |
552 |
#else
|
| 358 |
dsic.upv.es!antodo |
553 |
ierr = PetscViewerASCIIPrintf(viewer," shift: %g+%g i\n",PetscRealPart(st->sigma),PetscImaginaryPart(st->sigma));CHKERRQ(ierr);
|
| 6 |
dsic.upv.es!jroman |
554 |
#endif
|
| 344 |
dsic.upv.es!antodo |
555 |
switch (st->shift_matrix) {
|
| 1940 |
jroman |
556 |
case ST_MATMODE_COPY:
|
| 344 |
dsic.upv.es!antodo |
557 |
break;
|
| 1940 |
jroman |
558 |
case ST_MATMODE_INPLACE:
|
| 344 |
dsic.upv.es!antodo |
559 |
ierr = PetscViewerASCIIPrintf(viewer,"Shifting the matrix and unshifting at exit\n");CHKERRQ(ierr);
|
|
|
560 |
break;
|
| 1940 |
jroman |
561 |
case ST_MATMODE_SHELL:
|
| 344 |
dsic.upv.es!antodo |
562 |
ierr = PetscViewerASCIIPrintf(viewer,"Using a shell matrix\n");CHKERRQ(ierr);
|
|
|
563 |
break;
|
|
|
564 |
}
|
| 1940 |
jroman |
565 |
if (st->B && st->shift_matrix != ST_MATMODE_SHELL) {
|
| 344 |
dsic.upv.es!antodo |
566 |
switch (st->str) {
|
|
|
567 |
case SAME_NONZERO_PATTERN: str = "same nonzero pattern";break;
|
|
|
568 |
case DIFFERENT_NONZERO_PATTERN: str = "different nonzero pattern";break;
|
|
|
569 |
case SUBSET_NONZERO_PATTERN: str = "subset nonzero pattern";break;
|
| 2214 |
jroman |
570 |
default: SETERRQ(((PetscObject)st)->comm,1,"Wrong structure flag");
|
| 344 |
dsic.upv.es!antodo |
571 |
}
|
|
|
572 |
ierr = PetscViewerASCIIPrintf(viewer,"Matrices A and B have %s\n",str);CHKERRQ(ierr);
|
|
|
573 |
}
|
| 6 |
dsic.upv.es!jroman |
574 |
if (st->ops->view) {
|
|
|
575 |
ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
|
|
|
576 |
ierr = (*st->ops->view)(st,viewer);CHKERRQ(ierr);
|
|
|
577 |
ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
|
|
|
578 |
}
|
|
|
579 |
} else if (isstring) {
|
|
|
580 |
ierr = STGetType(st,&cstr);CHKERRQ(ierr);
|
|
|
581 |
ierr = PetscViewerStringSPrintf(viewer," %-7.7s",cstr);CHKERRQ(ierr);
|
|
|
582 |
if (st->ops->view) {ierr = (*st->ops->view)(st,viewer);CHKERRQ(ierr);}
|
|
|
583 |
} else {
|
| 2214 |
jroman |
584 |
SETERRQ1(((PetscObject)st)->comm,1,"Viewer type %s not supported by ST",((PetscObject)viewer)->type_name);
|
| 6 |
dsic.upv.es!jroman |
585 |
}
|
|
|
586 |
PetscFunctionReturn(0);
|
|
|
587 |
}
|
|
|
588 |
|
| 438 |
dsic.upv.es!antodo |
589 |
#undef __FUNCT__
|
|
|
590 |
#define __FUNCT__ "STView_Default"
|
| 476 |
dsic.upv.es!antodo |
591 |
PetscErrorCode STView_Default(ST st,PetscViewer viewer)
|
| 438 |
dsic.upv.es!antodo |
592 |
{
|
| 476 |
dsic.upv.es!antodo |
593 |
PetscErrorCode ierr;
|
| 2216 |
jroman |
594 |
PetscBool isascii,isstring;
|
| 438 |
dsic.upv.es!antodo |
595 |
|
|
|
596 |
PetscFunctionBegin;
|
| 2215 |
jroman |
597 |
ierr = PetscTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&isascii);CHKERRQ(ierr);
|
|
|
598 |
ierr = PetscTypeCompare((PetscObject)viewer,PETSCVIEWERSTRING,&isstring);CHKERRQ(ierr);
|
| 438 |
dsic.upv.es!antodo |
599 |
if (isascii) {
|
|
|
600 |
ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
|
|
|
601 |
ierr = PetscViewerASCIIPrintf(viewer,"Associated KSP object\n");CHKERRQ(ierr);
|
|
|
602 |
ierr = PetscViewerASCIIPrintf(viewer,"------------------------------\n");CHKERRQ(ierr);
|
|
|
603 |
ierr = KSPView(st->ksp,viewer);CHKERRQ(ierr);
|
|
|
604 |
ierr = PetscViewerASCIIPrintf(viewer,"------------------------------\n");CHKERRQ(ierr);
|
|
|
605 |
ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
|
|
|
606 |
} else if (isstring) {
|
|
|
607 |
ierr = KSPView(st->ksp,viewer);CHKERRQ(ierr);
|
|
|
608 |
}
|
|
|
609 |
PetscFunctionReturn(0);
|
|
|
610 |
}
|
|
|
611 |
|
| 6 |
dsic.upv.es!jroman |
612 |
/*MC
|
|
|
613 |
STRegisterDynamic - Adds a method to the spectral transformation package.
|
|
|
614 |
|
|
|
615 |
Synopsis:
|
| 1508 |
slepc |
616 |
STRegisterDynamic(char *name_solver,char *path,char *name_create,PetscErrorCode (*routine_create)(ST))
|
| 6 |
dsic.upv.es!jroman |
617 |
|
|
|
618 |
Not collective
|
|
|
619 |
|
|
|
620 |
Input Parameters:
|
|
|
621 |
+ name_solver - name of a new user-defined solver
|
|
|
622 |
. path - path (either absolute or relative) the library containing this solver
|
|
|
623 |
. name_create - name of routine to create method context
|
|
|
624 |
- routine_create - routine to create method context
|
|
|
625 |
|
|
|
626 |
Notes:
|
|
|
627 |
STRegisterDynamic() may be called multiple times to add several user-defined spectral transformations.
|
|
|
628 |
|
|
|
629 |
If dynamic libraries are used, then the fourth input argument (routine_create)
|
|
|
630 |
is ignored.
|
|
|
631 |
|
|
|
632 |
Sample usage:
|
|
|
633 |
.vb
|
|
|
634 |
STRegisterDynamic("my_solver","/home/username/my_lib/lib/libO/solaris/mylib.a",
|
|
|
635 |
"MySolverCreate",MySolverCreate);
|
|
|
636 |
.ve
|
|
|
637 |
|
|
|
638 |
Then, your solver can be chosen with the procedural interface via
|
|
|
639 |
$ STSetType(st,"my_solver")
|
|
|
640 |
or at runtime via the option
|
|
|
641 |
$ -st_type my_solver
|
|
|
642 |
|
|
|
643 |
Level: advanced
|
|
|
644 |
|
| 1389 |
slepc |
645 |
$PETSC_DIR, $PETSC_ARCH and $PETSC_LIB_DIR occuring in pathname will be replaced with appropriate values.
|
| 6 |
dsic.upv.es!jroman |
646 |
|
| 1389 |
slepc |
647 |
.seealso: STRegisterDestroy(), STRegisterAll()
|
| 6 |
dsic.upv.es!jroman |
648 |
M*/
|
|
|
649 |
|
|
|
650 |
#undef __FUNCT__
|
|
|
651 |
#define __FUNCT__ "STRegister"
|
| 1389 |
slepc |
652 |
/*@C
|
|
|
653 |
STRegister - See STRegisterDynamic()
|
|
|
654 |
|
|
|
655 |
Level: advanced
|
|
|
656 |
@*/
|
| 1508 |
slepc |
657 |
PetscErrorCode STRegister(const char *sname,const char *path,const char *name,PetscErrorCode (*function)(ST))
|
| 6 |
dsic.upv.es!jroman |
658 |
{
|
| 476 |
dsic.upv.es!antodo |
659 |
PetscErrorCode ierr;
|
|
|
660 |
char fullname[256];
|
| 6 |
dsic.upv.es!jroman |
661 |
|
|
|
662 |
PetscFunctionBegin;
|
|
|
663 |
ierr = PetscFListConcat(path,name,fullname);CHKERRQ(ierr);
|
|
|
664 |
ierr = PetscFListAdd(&STList,sname,fullname,(void (*)(void))function);CHKERRQ(ierr);
|
|
|
665 |
PetscFunctionReturn(0);
|
|
|
666 |
}
|
| 1389 |
slepc |
667 |
|
|
|
668 |
#undef __FUNCT__
|
|
|
669 |
#define __FUNCT__ "STRegisterDestroy"
|
|
|
670 |
/*@
|
|
|
671 |
STRegisterDestroy - Frees the list of ST methods that were
|
|
|
672 |
registered by STRegisterDynamic().
|
|
|
673 |
|
|
|
674 |
Not Collective
|
|
|
675 |
|
|
|
676 |
Level: advanced
|
|
|
677 |
|
|
|
678 |
.seealso: STRegisterDynamic(), STRegisterAll()
|
|
|
679 |
@*/
|
|
|
680 |
PetscErrorCode STRegisterDestroy(void)
|
|
|
681 |
{
|
|
|
682 |
PetscErrorCode ierr;
|
|
|
683 |
|
|
|
684 |
PetscFunctionBegin;
|
|
|
685 |
ierr = PetscFListDestroy(&STList);CHKERRQ(ierr);
|
|
|
686 |
ierr = STRegisterAll(PETSC_NULL);CHKERRQ(ierr);
|
|
|
687 |
PetscFunctionReturn(0);
|
|
|
688 |
}
|