| 1302 |
slepc |
1 |
/*
|
|
|
2 |
Basic routines
|
| 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 |
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
| 1302 |
slepc |
22 |
*/
|
| 1376 |
slepc |
23 |
|
| 2729 |
jroman |
24 |
#include <slepc-private/ipimpl.h> /*I "slepcip.h" I*/
|
| 1302 |
slepc |
25 |
|
| 2373 |
jroman |
26 |
PetscFList IPList = 0;
|
| 2376 |
jroman |
27 |
PetscBool IPRegisterAllCalled = PETSC_FALSE;
|
| 2373 |
jroman |
28 |
PetscClassId IP_CLASSID = 0;
|
|
|
29 |
PetscLogEvent IP_InnerProduct = 0,IP_Orthogonalize = 0,IP_ApplyMatrix = 0;
|
|
|
30 |
static PetscBool IPPackageInitialized = PETSC_FALSE;
|
| 1302 |
slepc |
31 |
|
|
|
32 |
#undef __FUNCT__
|
| 2373 |
jroman |
33 |
#define __FUNCT__ "IPFinalizePackage"
|
|
|
34 |
/*@C
|
|
|
35 |
IPFinalizePackage - This function destroys everything in the Slepc interface
|
|
|
36 |
to the IP package. It is called from SlepcFinalize().
|
|
|
37 |
|
|
|
38 |
Level: developer
|
|
|
39 |
|
|
|
40 |
.seealso: SlepcFinalize()
|
|
|
41 |
@*/
|
|
|
42 |
PetscErrorCode IPFinalizePackage(void)
|
|
|
43 |
{
|
|
|
44 |
PetscFunctionBegin;
|
|
|
45 |
IPPackageInitialized = PETSC_FALSE;
|
|
|
46 |
IPList = 0;
|
| 2376 |
jroman |
47 |
IPRegisterAllCalled = PETSC_FALSE;
|
| 2373 |
jroman |
48 |
PetscFunctionReturn(0);
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
#undef __FUNCT__
|
| 1329 |
slepc |
52 |
#define __FUNCT__ "IPInitializePackage"
|
| 1345 |
slepc |
53 |
/*@C
|
|
|
54 |
IPInitializePackage - This function initializes everything in the IP package. It is called
|
|
|
55 |
from PetscDLLibraryRegister() when using dynamic libraries, and on the first call to IPCreate()
|
|
|
56 |
when using static libraries.
|
|
|
57 |
|
|
|
58 |
Input Parameter:
|
|
|
59 |
path - The dynamic library path, or PETSC_NULL
|
|
|
60 |
|
|
|
61 |
Level: developer
|
|
|
62 |
|
|
|
63 |
.seealso: SlepcInitialize()
|
|
|
64 |
@*/
|
| 2212 |
jroman |
65 |
PetscErrorCode IPInitializePackage(const char *path)
|
| 1302 |
slepc |
66 |
{
|
| 2317 |
jroman |
67 |
char logList[256];
|
|
|
68 |
char *className;
|
|
|
69 |
PetscBool opt;
|
|
|
70 |
PetscErrorCode ierr;
|
| 1302 |
slepc |
71 |
|
|
|
72 |
PetscFunctionBegin;
|
| 2373 |
jroman |
73 |
if (IPPackageInitialized) PetscFunctionReturn(0);
|
|
|
74 |
IPPackageInitialized = PETSC_TRUE;
|
| 1302 |
slepc |
75 |
/* Register Classes */
|
| 2213 |
jroman |
76 |
ierr = PetscClassIdRegister("Inner product",&IP_CLASSID);CHKERRQ(ierr);
|
| 2373 |
jroman |
77 |
/* Register Constructors */
|
|
|
78 |
ierr = IPRegisterAll(path);CHKERRQ(ierr);
|
| 1302 |
slepc |
79 |
/* Register Events */
|
| 2330 |
jroman |
80 |
ierr = PetscLogEventRegister("IPOrthogonalize",IP_CLASSID,&IP_Orthogonalize);CHKERRQ(ierr);
|
|
|
81 |
ierr = PetscLogEventRegister("IPInnerProduct",IP_CLASSID,&IP_InnerProduct);CHKERRQ(ierr);
|
|
|
82 |
ierr = PetscLogEventRegister("IPApplyMatrix",IP_CLASSID,&IP_ApplyMatrix);CHKERRQ(ierr);
|
| 1302 |
slepc |
83 |
/* Process info exclusions */
|
| 2331 |
jroman |
84 |
ierr = PetscOptionsGetString(PETSC_NULL,"-info_exclude",logList,256,&opt);CHKERRQ(ierr);
|
| 1302 |
slepc |
85 |
if (opt) {
|
| 2331 |
jroman |
86 |
ierr = PetscStrstr(logList,"ip",&className);CHKERRQ(ierr);
|
| 1302 |
slepc |
87 |
if (className) {
|
| 2213 |
jroman |
88 |
ierr = PetscInfoDeactivateClass(IP_CLASSID);CHKERRQ(ierr);
|
| 1302 |
slepc |
89 |
}
|
|
|
90 |
}
|
|
|
91 |
/* Process summary exclusions */
|
| 2331 |
jroman |
92 |
ierr = PetscOptionsGetString(PETSC_NULL,"-log_summary_exclude",logList,256,&opt);CHKERRQ(ierr);
|
| 1302 |
slepc |
93 |
if (opt) {
|
| 2331 |
jroman |
94 |
ierr = PetscStrstr(logList,"ip",&className);CHKERRQ(ierr);
|
| 1302 |
slepc |
95 |
if (className) {
|
| 2213 |
jroman |
96 |
ierr = PetscLogEventDeactivateClass(IP_CLASSID);CHKERRQ(ierr);
|
| 1302 |
slepc |
97 |
}
|
|
|
98 |
}
|
| 2373 |
jroman |
99 |
ierr = PetscRegisterFinalize(IPFinalizePackage);CHKERRQ(ierr);
|
| 1302 |
slepc |
100 |
PetscFunctionReturn(0);
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
#undef __FUNCT__
|
|
|
104 |
#define __FUNCT__ "IPCreate"
|
| 1345 |
slepc |
105 |
/*@C
|
|
|
106 |
IPCreate - Creates an IP context.
|
|
|
107 |
|
|
|
108 |
Collective on MPI_Comm
|
|
|
109 |
|
|
|
110 |
Input Parameter:
|
|
|
111 |
. comm - MPI communicator
|
|
|
112 |
|
|
|
113 |
Output Parameter:
|
| 1349 |
slepc |
114 |
. newip - location to put the IP context
|
| 1345 |
slepc |
115 |
|
|
|
116 |
Level: beginner
|
|
|
117 |
|
| 1349 |
slepc |
118 |
Note:
|
|
|
119 |
IP objects are not intended for normal users but only for
|
|
|
120 |
advanced user that for instance implement their own solvers.
|
|
|
121 |
|
| 1345 |
slepc |
122 |
.seealso: IPDestroy(), IP
|
|
|
123 |
@*/
|
| 1302 |
slepc |
124 |
PetscErrorCode IPCreate(MPI_Comm comm,IP *newip)
|
|
|
125 |
{
|
| 2317 |
jroman |
126 |
IP ip;
|
| 1345 |
slepc |
127 |
PetscErrorCode ierr;
|
| 1302 |
slepc |
128 |
|
|
|
129 |
PetscFunctionBegin;
|
|
|
130 |
PetscValidPointer(newip,2);
|
| 2469 |
jroman |
131 |
ierr = PetscHeaderCreate(ip,_p_IP,struct _IPOps,IP_CLASSID,-1,"IP","Inner Product","IP",comm,IPDestroy,IPView);CHKERRQ(ierr);
|
| 1302 |
slepc |
132 |
*newip = ip;
|
| 2370 |
jroman |
133 |
ip->orthog_type = IP_ORTHOG_CGS;
|
|
|
134 |
ip->orthog_ref = IP_ORTHOG_REFINE_IFNEEDED;
|
| 1302 |
slepc |
135 |
ip->orthog_eta = 0.7071;
|
|
|
136 |
ip->innerproducts = 0;
|
| 1329 |
slepc |
137 |
ip->matrix = PETSC_NULL;
|
| 1361 |
slepc |
138 |
ip->Bx = PETSC_NULL;
|
|
|
139 |
ip->xid = 0;
|
|
|
140 |
ip->xstate = 0;
|
| 1302 |
slepc |
141 |
PetscFunctionReturn(0);
|
|
|
142 |
}
|
|
|
143 |
|
|
|
144 |
#undef __FUNCT__
|
| 1316 |
slepc |
145 |
#define __FUNCT__ "IPSetOptionsPrefix"
|
| 1345 |
slepc |
146 |
/*@C
|
|
|
147 |
IPSetOptionsPrefix - Sets the prefix used for searching for all
|
|
|
148 |
IP options in the database.
|
|
|
149 |
|
| 2328 |
jroman |
150 |
Logically Collective on IP
|
| 1345 |
slepc |
151 |
|
|
|
152 |
Input Parameters:
|
|
|
153 |
+ ip - the innerproduct context
|
|
|
154 |
- prefix - the prefix string to prepend to all IP option requests
|
|
|
155 |
|
|
|
156 |
Notes:
|
|
|
157 |
A hyphen (-) must NOT be given at the beginning of the prefix name.
|
|
|
158 |
The first character of all runtime options is AUTOMATICALLY the
|
|
|
159 |
hyphen.
|
|
|
160 |
|
|
|
161 |
Level: advanced
|
|
|
162 |
|
|
|
163 |
.seealso: IPAppendOptionsPrefix()
|
|
|
164 |
@*/
|
| 1316 |
slepc |
165 |
PetscErrorCode IPSetOptionsPrefix(IP ip,const char *prefix)
|
|
|
166 |
{
|
|
|
167 |
PetscErrorCode ierr;
|
| 2317 |
jroman |
168 |
|
| 1316 |
slepc |
169 |
PetscFunctionBegin;
|
| 2213 |
jroman |
170 |
PetscValidHeaderSpecific(ip,IP_CLASSID,1);
|
| 1316 |
slepc |
171 |
ierr = PetscObjectSetOptionsPrefix((PetscObject)ip,prefix);CHKERRQ(ierr);
|
|
|
172 |
PetscFunctionReturn(0);
|
|
|
173 |
}
|
|
|
174 |
|
|
|
175 |
#undef __FUNCT__
|
| 1302 |
slepc |
176 |
#define __FUNCT__ "IPAppendOptionsPrefix"
|
| 1345 |
slepc |
177 |
/*@C
|
|
|
178 |
IPAppendOptionsPrefix - Appends to the prefix used for searching for all
|
|
|
179 |
IP options in the database.
|
|
|
180 |
|
| 2328 |
jroman |
181 |
Logically Collective on IP
|
| 1345 |
slepc |
182 |
|
|
|
183 |
Input Parameters:
|
|
|
184 |
+ ip - the innerproduct context
|
|
|
185 |
- prefix - the prefix string to prepend to all IP option requests
|
|
|
186 |
|
|
|
187 |
Notes:
|
|
|
188 |
A hyphen (-) must NOT be given at the beginning of the prefix name.
|
|
|
189 |
The first character of all runtime options is AUTOMATICALLY the hyphen.
|
|
|
190 |
|
|
|
191 |
Level: advanced
|
|
|
192 |
|
|
|
193 |
.seealso: IPSetOptionsPrefix()
|
|
|
194 |
@*/
|
| 1302 |
slepc |
195 |
PetscErrorCode IPAppendOptionsPrefix(IP ip,const char *prefix)
|
|
|
196 |
{
|
|
|
197 |
PetscErrorCode ierr;
|
| 2317 |
jroman |
198 |
|
| 1302 |
slepc |
199 |
PetscFunctionBegin;
|
| 2213 |
jroman |
200 |
PetscValidHeaderSpecific(ip,IP_CLASSID,1);
|
| 1302 |
slepc |
201 |
ierr = PetscObjectAppendOptionsPrefix((PetscObject)ip,prefix);CHKERRQ(ierr);
|
|
|
202 |
PetscFunctionReturn(0);
|
|
|
203 |
}
|
|
|
204 |
|
| 1518 |
slepc |
205 |
#undef __FUNCT__
|
|
|
206 |
#define __FUNCT__ "IPGetOptionsPrefix"
|
|
|
207 |
/*@C
|
|
|
208 |
IPGetOptionsPrefix - Gets the prefix used for searching for all
|
|
|
209 |
IP options in the database.
|
|
|
210 |
|
|
|
211 |
Not Collective
|
|
|
212 |
|
|
|
213 |
Input Parameters:
|
|
|
214 |
. ip - the innerproduct context
|
|
|
215 |
|
|
|
216 |
Output Parameters:
|
|
|
217 |
. prefix - pointer to the prefix string used is returned
|
|
|
218 |
|
|
|
219 |
Notes: On the fortran side, the user should pass in a string 'prefix' of
|
|
|
220 |
sufficient length to hold the prefix.
|
|
|
221 |
|
|
|
222 |
Level: advanced
|
|
|
223 |
|
|
|
224 |
.seealso: IPSetOptionsPrefix(), IPAppendOptionsPrefix()
|
|
|
225 |
@*/
|
|
|
226 |
PetscErrorCode IPGetOptionsPrefix(IP ip,const char *prefix[])
|
|
|
227 |
{
|
| 2317 |
jroman |
228 |
PetscErrorCode ierr;
|
|
|
229 |
|
|
|
230 |
PetscFunctionBegin;
|
|
|
231 |
PetscValidHeaderSpecific(ip,IP_CLASSID,1);
|
|
|
232 |
PetscValidPointer(prefix,2);
|
| 2331 |
jroman |
233 |
ierr = PetscObjectGetOptionsPrefix((PetscObject)ip,prefix);CHKERRQ(ierr);
|
| 2317 |
jroman |
234 |
PetscFunctionReturn(0);
|
| 1518 |
slepc |
235 |
}
|
|
|
236 |
|
| 1302 |
slepc |
237 |
#undef __FUNCT__
|
| 2373 |
jroman |
238 |
#define __FUNCT__ "IPSetType"
|
|
|
239 |
/*@C
|
|
|
240 |
IPSetType - Selects the type for the IP object.
|
|
|
241 |
|
|
|
242 |
Logically Collective on IP
|
|
|
243 |
|
|
|
244 |
Input Parameter:
|
|
|
245 |
+ ip - the inner product context.
|
|
|
246 |
- type - a known type
|
|
|
247 |
|
|
|
248 |
Notes:
|
| 2746 |
jroman |
249 |
Three types are available: IPBILINEAR, IPSESQUILINEAR, and IPINDEFINITE.
|
| 2373 |
jroman |
250 |
|
|
|
251 |
For complex scalars, the default is a sesquilinear form (x,y)=x^H*M*y and it is
|
|
|
252 |
also possible to choose a bilinear form (x,y)=x^T*M*y (without complex conjugation).
|
|
|
253 |
The latter could be useful e.g. in complex-symmetric eigensolvers.
|
|
|
254 |
|
|
|
255 |
In the case of real scalars, only the bilinear form (x,y)=x^T*M*y is available.
|
|
|
256 |
|
| 2746 |
jroman |
257 |
The indefinite inner product is reserved for the case of an indefinite
|
|
|
258 |
matrix M. This is used for instance in symmetric-indefinite eigenproblems.
|
|
|
259 |
|
| 2373 |
jroman |
260 |
Level: advanced
|
|
|
261 |
|
|
|
262 |
.seealso: IPGetType()
|
|
|
263 |
|
|
|
264 |
@*/
|
|
|
265 |
PetscErrorCode IPSetType(IP ip,const IPType type)
|
|
|
266 |
{
|
|
|
267 |
PetscErrorCode ierr,(*r)(IP);
|
|
|
268 |
PetscBool match;
|
|
|
269 |
|
|
|
270 |
PetscFunctionBegin;
|
|
|
271 |
PetscValidHeaderSpecific(ip,IP_CLASSID,1);
|
|
|
272 |
PetscValidCharPointer(type,2);
|
|
|
273 |
|
| 2823 |
jroman |
274 |
ierr = PetscObjectTypeCompare((PetscObject)ip,type,&match);CHKERRQ(ierr);
|
| 2373 |
jroman |
275 |
if (match) PetscFunctionReturn(0);
|
|
|
276 |
|
|
|
277 |
ierr = PetscFListFind(IPList,((PetscObject)ip)->comm,type,PETSC_TRUE,(void (**)(void))&r);CHKERRQ(ierr);
|
|
|
278 |
if (!r) SETERRQ1(((PetscObject)ip)->comm,PETSC_ERR_ARG_UNKNOWN_TYPE,"Unable to find requested IP type %s",type);
|
|
|
279 |
|
|
|
280 |
ierr = PetscMemzero(ip->ops,sizeof(struct _IPOps));CHKERRQ(ierr);
|
|
|
281 |
|
|
|
282 |
ierr = PetscObjectChangeTypeName((PetscObject)ip,type);CHKERRQ(ierr);
|
|
|
283 |
ierr = (*r)(ip);CHKERRQ(ierr);
|
|
|
284 |
PetscFunctionReturn(0);
|
|
|
285 |
}
|
|
|
286 |
|
|
|
287 |
#undef __FUNCT__
|
|
|
288 |
#define __FUNCT__ "IPGetType"
|
|
|
289 |
/*@C
|
|
|
290 |
IPGetType - Gets the IP type name (as a string) from the IP context.
|
|
|
291 |
|
|
|
292 |
Not Collective
|
|
|
293 |
|
|
|
294 |
Input Parameter:
|
|
|
295 |
. ip - the inner product context
|
|
|
296 |
|
|
|
297 |
Output Parameter:
|
|
|
298 |
. name - name of the inner product
|
|
|
299 |
|
|
|
300 |
Level: advanced
|
|
|
301 |
|
|
|
302 |
.seealso: IPSetType()
|
|
|
303 |
|
|
|
304 |
@*/
|
|
|
305 |
PetscErrorCode IPGetType(IP ip,const IPType *type)
|
|
|
306 |
{
|
|
|
307 |
PetscFunctionBegin;
|
|
|
308 |
PetscValidHeaderSpecific(ip,IP_CLASSID,1);
|
|
|
309 |
PetscValidPointer(type,2);
|
|
|
310 |
*type = ((PetscObject)ip)->type_name;
|
|
|
311 |
PetscFunctionReturn(0);
|
|
|
312 |
}
|
|
|
313 |
|
|
|
314 |
#undef __FUNCT__
|
| 2412 |
jroman |
315 |
#define __FUNCT__ "IPSetDefaultType_Private"
|
|
|
316 |
/*
|
|
|
317 |
Sets the default IP type, depending on whether complex arithmetic
|
|
|
318 |
is used or not.
|
|
|
319 |
*/
|
|
|
320 |
PetscErrorCode IPSetDefaultType_Private(IP ip)
|
|
|
321 |
{
|
|
|
322 |
PetscErrorCode ierr;
|
|
|
323 |
|
|
|
324 |
PetscFunctionBegin;
|
|
|
325 |
PetscValidHeaderSpecific(ip,IP_CLASSID,1);
|
|
|
326 |
#if defined(PETSC_USE_COMPLEX)
|
|
|
327 |
ierr = IPSetType(ip,IPSESQUILINEAR);CHKERRQ(ierr);
|
|
|
328 |
#else
|
|
|
329 |
ierr = IPSetType(ip,IPBILINEAR);CHKERRQ(ierr);
|
|
|
330 |
#endif
|
|
|
331 |
PetscFunctionReturn(0);
|
|
|
332 |
}
|
|
|
333 |
|
|
|
334 |
#undef __FUNCT__
|
| 1302 |
slepc |
335 |
#define __FUNCT__ "IPSetFromOptions"
|
| 1345 |
slepc |
336 |
/*@
|
|
|
337 |
IPSetFromOptions - Sets IP options from the options database.
|
|
|
338 |
|
|
|
339 |
Collective on IP
|
|
|
340 |
|
|
|
341 |
Input Parameters:
|
|
|
342 |
. ip - the innerproduct context
|
|
|
343 |
|
|
|
344 |
Notes:
|
|
|
345 |
To see all options, run your program with the -help option.
|
|
|
346 |
|
|
|
347 |
Level: beginner
|
|
|
348 |
@*/
|
| 1302 |
slepc |
349 |
PetscErrorCode IPSetFromOptions(IP ip)
|
|
|
350 |
{
|
| 2331 |
jroman |
351 |
const char *orth_list[2] = {"mgs","cgs"};
|
|
|
352 |
const char *ref_list[3] = {"never","ifneeded","always"};
|
| 1302 |
slepc |
353 |
PetscReal r;
|
|
|
354 |
PetscInt i,j;
|
| 2317 |
jroman |
355 |
PetscErrorCode ierr;
|
| 1302 |
slepc |
356 |
|
|
|
357 |
PetscFunctionBegin;
|
| 2213 |
jroman |
358 |
PetscValidHeaderSpecific(ip,IP_CLASSID,1);
|
| 2376 |
jroman |
359 |
if (!IPRegisterAllCalled) { ierr = IPRegisterAll(PETSC_NULL);CHKERRQ(ierr); }
|
| 2412 |
jroman |
360 |
/* Set default type (we do not allow changing it with -ip_type) */
|
| 2373 |
jroman |
361 |
if (!((PetscObject)ip)->type_name) {
|
| 2412 |
jroman |
362 |
ierr = IPSetDefaultType_Private(ip);CHKERRQ(ierr);
|
| 2373 |
jroman |
363 |
}
|
| 1422 |
slepc |
364 |
ierr = PetscOptionsBegin(((PetscObject)ip)->comm,((PetscObject)ip)->prefix,"Inner Product (IP) Options","IP");CHKERRQ(ierr);
|
| 2373 |
jroman |
365 |
i = ip->orthog_type;
|
|
|
366 |
ierr = PetscOptionsEList("-ip_orthog_type","Orthogonalization method","IPSetOrthogonalization",orth_list,2,orth_list[i],&i,PETSC_NULL);CHKERRQ(ierr);
|
|
|
367 |
j = ip->orthog_ref;
|
|
|
368 |
ierr = PetscOptionsEList("-ip_orthog_refine","Iterative refinement mode during orthogonalization","IPSetOrthogonalization",ref_list,3,ref_list[j],&j,PETSC_NULL);CHKERRQ(ierr);
|
|
|
369 |
r = ip->orthog_eta;
|
|
|
370 |
ierr = PetscOptionsReal("-ip_orthog_eta","Parameter of iterative refinement during orthogonalization","IPSetOrthogonalization",r,&r,PETSC_NULL);CHKERRQ(ierr);
|
|
|
371 |
ierr = IPSetOrthogonalization(ip,(IPOrthogType)i,(IPOrthogRefineType)j,r);CHKERRQ(ierr);
|
| 2384 |
jroman |
372 |
ierr = PetscObjectProcessOptionsHandlers((PetscObject)ip);CHKERRQ(ierr);
|
| 1302 |
slepc |
373 |
ierr = PetscOptionsEnd();CHKERRQ(ierr);
|
|
|
374 |
PetscFunctionReturn(0);
|
|
|
375 |
}
|
|
|
376 |
|
|
|
377 |
#undef __FUNCT__
|
|
|
378 |
#define __FUNCT__ "IPSetOrthogonalization"
|
| 1345 |
slepc |
379 |
/*@
|
|
|
380 |
IPSetOrthogonalization - Specifies the type of orthogonalization technique
|
|
|
381 |
to be used (classical or modified Gram-Schmidt with or without refinement).
|
|
|
382 |
|
| 2328 |
jroman |
383 |
Logically Collective on IP
|
| 1345 |
slepc |
384 |
|
|
|
385 |
Input Parameters:
|
| 2370 |
jroman |
386 |
+ ip - the innerproduct context
|
|
|
387 |
. type - the type of orthogonalization technique
|
|
|
388 |
. refine - type of refinement
|
|
|
389 |
- eta - parameter for selective refinement
|
| 1345 |
slepc |
390 |
|
|
|
391 |
Options Database Keys:
|
| 2370 |
jroman |
392 |
+ -orthog_type <type> - Where <type> is cgs for Classical Gram-Schmidt orthogonalization
|
|
|
393 |
(default) or mgs for Modified Gram-Schmidt orthogonalization
|
|
|
394 |
. -orthog_refine <type> - Where <type> is one of never, ifneeded (default) or always
|
| 1345 |
slepc |
395 |
- -orthog_eta <eta> - For setting the value of eta
|
|
|
396 |
|
|
|
397 |
Notes:
|
|
|
398 |
The default settings work well for most problems.
|
|
|
399 |
|
|
|
400 |
The parameter eta should be a real value between 0 and 1 (or PETSC_DEFAULT).
|
|
|
401 |
The value of eta is used only when the refinement type is "ifneeded".
|
|
|
402 |
|
|
|
403 |
When using several processors, MGS is likely to result in bad scalability.
|
|
|
404 |
|
|
|
405 |
Level: advanced
|
|
|
406 |
|
| 2370 |
jroman |
407 |
.seealso: IPOrthogonalize(), IPGetOrthogonalization(), IPOrthogType,
|
|
|
408 |
IPOrthogRefineType
|
| 1345 |
slepc |
409 |
@*/
|
| 2370 |
jroman |
410 |
PetscErrorCode IPSetOrthogonalization(IP ip,IPOrthogType type,IPOrthogRefineType refine,PetscReal eta)
|
| 1302 |
slepc |
411 |
{
|
|
|
412 |
PetscFunctionBegin;
|
| 2213 |
jroman |
413 |
PetscValidHeaderSpecific(ip,IP_CLASSID,1);
|
| 2326 |
jroman |
414 |
PetscValidLogicalCollectiveEnum(ip,type,2);
|
| 2370 |
jroman |
415 |
PetscValidLogicalCollectiveEnum(ip,refine,3);
|
| 2326 |
jroman |
416 |
PetscValidLogicalCollectiveReal(ip,eta,4);
|
| 1302 |
slepc |
417 |
switch (type) {
|
| 2370 |
jroman |
418 |
case IP_ORTHOG_CGS:
|
|
|
419 |
case IP_ORTHOG_MGS:
|
| 1302 |
slepc |
420 |
ip->orthog_type = type;
|
|
|
421 |
break;
|
|
|
422 |
default:
|
| 2214 |
jroman |
423 |
SETERRQ(((PetscObject)ip)->comm,PETSC_ERR_ARG_WRONG,"Unknown orthogonalization type");
|
| 1302 |
slepc |
424 |
}
|
| 2370 |
jroman |
425 |
switch (refine) {
|
|
|
426 |
case IP_ORTHOG_REFINE_NEVER:
|
|
|
427 |
case IP_ORTHOG_REFINE_IFNEEDED:
|
|
|
428 |
case IP_ORTHOG_REFINE_ALWAYS:
|
|
|
429 |
ip->orthog_ref = refine;
|
| 1302 |
slepc |
430 |
break;
|
|
|
431 |
default:
|
| 2214 |
jroman |
432 |
SETERRQ(((PetscObject)ip)->comm,PETSC_ERR_ARG_WRONG,"Unknown refinement type");
|
| 1302 |
slepc |
433 |
}
|
|
|
434 |
if (eta == PETSC_DEFAULT) {
|
|
|
435 |
ip->orthog_eta = 0.7071;
|
|
|
436 |
} else {
|
| 2214 |
jroman |
437 |
if (eta <= 0.0 || eta > 1.0) SETERRQ(((PetscObject)ip)->comm,PETSC_ERR_ARG_OUTOFRANGE,"Invalid eta value");
|
| 1302 |
slepc |
438 |
ip->orthog_eta = eta;
|
|
|
439 |
}
|
|
|
440 |
PetscFunctionReturn(0);
|
|
|
441 |
}
|
|
|
442 |
|
|
|
443 |
#undef __FUNCT__
|
| 1345 |
slepc |
444 |
#define __FUNCT__ "IPGetOrthogonalization"
|
|
|
445 |
/*@C
|
|
|
446 |
IPGetOrthogonalization - Gets the orthogonalization settings from the
|
|
|
447 |
IP object.
|
|
|
448 |
|
|
|
449 |
Not Collective
|
|
|
450 |
|
|
|
451 |
Input Parameter:
|
|
|
452 |
. ip - inner product context
|
|
|
453 |
|
|
|
454 |
Output Parameter:
|
| 2370 |
jroman |
455 |
+ type - type of orthogonalization technique
|
|
|
456 |
. refine - type of refinement
|
|
|
457 |
- eta - parameter for selective refinement
|
| 1345 |
slepc |
458 |
|
|
|
459 |
Level: advanced
|
|
|
460 |
|
| 2370 |
jroman |
461 |
.seealso: IPOrthogonalize(), IPSetOrthogonalization(), IPOrthogType,
|
|
|
462 |
IPOrthogRefineType
|
| 1345 |
slepc |
463 |
@*/
|
| 2370 |
jroman |
464 |
PetscErrorCode IPGetOrthogonalization(IP ip,IPOrthogType *type,IPOrthogRefineType *refine,PetscReal *eta)
|
| 1345 |
slepc |
465 |
{
|
|
|
466 |
PetscFunctionBegin;
|
| 2213 |
jroman |
467 |
PetscValidHeaderSpecific(ip,IP_CLASSID,1);
|
| 2370 |
jroman |
468 |
if (type) *type = ip->orthog_type;
|
|
|
469 |
if (refine) *refine = ip->orthog_ref;
|
|
|
470 |
if (eta) *eta = ip->orthog_eta;
|
| 1345 |
slepc |
471 |
PetscFunctionReturn(0);
|
|
|
472 |
}
|
|
|
473 |
|
|
|
474 |
#undef __FUNCT__
|
| 1302 |
slepc |
475 |
#define __FUNCT__ "IPView"
|
| 1345 |
slepc |
476 |
/*@C
|
|
|
477 |
IPView - Prints the IP data structure.
|
|
|
478 |
|
|
|
479 |
Collective on IP
|
|
|
480 |
|
|
|
481 |
Input Parameters:
|
|
|
482 |
+ ip - the innerproduct context
|
|
|
483 |
- viewer - optional visualization context
|
|
|
484 |
|
|
|
485 |
Note:
|
|
|
486 |
The available visualization contexts include
|
|
|
487 |
+ PETSC_VIEWER_STDOUT_SELF - standard output (default)
|
|
|
488 |
- PETSC_VIEWER_STDOUT_WORLD - synchronized standard
|
|
|
489 |
output where only the first processor opens
|
|
|
490 |
the file. All other processors send their
|
|
|
491 |
data to the first processor to print.
|
|
|
492 |
|
|
|
493 |
The user can open an alternative visualization context with
|
|
|
494 |
PetscViewerASCIIOpen() - output to a specified file.
|
|
|
495 |
|
|
|
496 |
Level: beginner
|
|
|
497 |
|
| 2242 |
jroman |
498 |
.seealso: EPSView(), SVDView(), PetscViewerASCIIOpen()
|
| 1345 |
slepc |
499 |
@*/
|
| 1302 |
slepc |
500 |
PetscErrorCode IPView(IP ip,PetscViewer viewer)
|
|
|
501 |
{
|
| 2317 |
jroman |
502 |
PetscBool isascii;
|
| 1302 |
slepc |
503 |
PetscErrorCode ierr;
|
|
|
504 |
|
|
|
505 |
PetscFunctionBegin;
|
| 2213 |
jroman |
506 |
PetscValidHeaderSpecific(ip,IP_CLASSID,1);
|
| 1422 |
slepc |
507 |
if (!viewer) viewer = PETSC_VIEWER_STDOUT_(((PetscObject)ip)->comm);
|
| 2213 |
jroman |
508 |
PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,2);
|
| 1302 |
slepc |
509 |
PetscCheckSameComm(ip,1,viewer,2);
|
| 2823 |
jroman |
510 |
ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&isascii);CHKERRQ(ierr);
|
| 1302 |
slepc |
511 |
if (isascii) {
|
| 2224 |
jroman |
512 |
ierr = PetscObjectPrintClassNamePrefixType((PetscObject)ip,viewer,"IP Object");CHKERRQ(ierr);
|
| 1302 |
slepc |
513 |
ierr = PetscViewerASCIIPrintf(viewer," orthogonalization method: ");CHKERRQ(ierr);
|
|
|
514 |
switch (ip->orthog_type) {
|
| 2370 |
jroman |
515 |
case IP_ORTHOG_MGS:
|
| 1302 |
slepc |
516 |
ierr = PetscViewerASCIIPrintf(viewer,"modified Gram-Schmidt\n");CHKERRQ(ierr);
|
|
|
517 |
break;
|
| 2370 |
jroman |
518 |
case IP_ORTHOG_CGS:
|
| 1302 |
slepc |
519 |
ierr = PetscViewerASCIIPrintf(viewer,"classical Gram-Schmidt\n");CHKERRQ(ierr);
|
|
|
520 |
break;
|
| 2214 |
jroman |
521 |
default: SETERRQ(((PetscObject)ip)->comm,1,"Wrong value of ip->orth_type");
|
| 1302 |
slepc |
522 |
}
|
|
|
523 |
ierr = PetscViewerASCIIPrintf(viewer," orthogonalization refinement: ");CHKERRQ(ierr);
|
|
|
524 |
switch (ip->orthog_ref) {
|
| 2370 |
jroman |
525 |
case IP_ORTHOG_REFINE_NEVER:
|
| 1302 |
slepc |
526 |
ierr = PetscViewerASCIIPrintf(viewer,"never\n");CHKERRQ(ierr);
|
|
|
527 |
break;
|
| 2370 |
jroman |
528 |
case IP_ORTHOG_REFINE_IFNEEDED:
|
| 2394 |
jroman |
529 |
ierr = PetscViewerASCIIPrintf(viewer,"if needed (eta: %G)\n",ip->orthog_eta);CHKERRQ(ierr);
|
| 1302 |
slepc |
530 |
break;
|
| 2370 |
jroman |
531 |
case IP_ORTHOG_REFINE_ALWAYS:
|
| 1302 |
slepc |
532 |
ierr = PetscViewerASCIIPrintf(viewer,"always\n");CHKERRQ(ierr);
|
|
|
533 |
break;
|
| 2214 |
jroman |
534 |
default: SETERRQ(((PetscObject)ip)->comm,1,"Wrong value of ip->orth_ref");
|
| 1302 |
slepc |
535 |
}
|
| 2379 |
jroman |
536 |
if (ip->matrix) {
|
|
|
537 |
ierr = PetscViewerPushFormat(viewer,PETSC_VIEWER_ASCII_INFO);CHKERRQ(ierr);
|
|
|
538 |
ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
|
|
|
539 |
ierr = MatView(ip->matrix,viewer);CHKERRQ(ierr);
|
|
|
540 |
ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
|
|
|
541 |
ierr = PetscViewerPopFormat(viewer);CHKERRQ(ierr);
|
|
|
542 |
}
|
| 2762 |
jroman |
543 |
} else SETERRQ1(((PetscObject)ip)->comm,1,"Viewer type %s not supported for IP",((PetscObject)viewer)->type_name);
|
| 1302 |
slepc |
544 |
PetscFunctionReturn(0);
|
|
|
545 |
}
|
|
|
546 |
|
|
|
547 |
#undef __FUNCT__
|
| 2348 |
jroman |
548 |
#define __FUNCT__ "IPReset"
|
| 2760 |
jroman |
549 |
/*@
|
| 2348 |
jroman |
550 |
IPReset - Resets the IP context to the initial state.
|
|
|
551 |
|
|
|
552 |
Collective on IP
|
|
|
553 |
|
|
|
554 |
Input Parameter:
|
|
|
555 |
. ip - the inner product context
|
|
|
556 |
|
|
|
557 |
Level: advanced
|
|
|
558 |
|
|
|
559 |
.seealso: IPDestroy()
|
|
|
560 |
@*/
|
|
|
561 |
PetscErrorCode IPReset(IP ip)
|
|
|
562 |
{
|
|
|
563 |
PetscErrorCode ierr;
|
|
|
564 |
|
|
|
565 |
PetscFunctionBegin;
|
|
|
566 |
PetscValidHeaderSpecific(ip,IP_CLASSID,1);
|
|
|
567 |
ierr = MatDestroy(&ip->matrix);CHKERRQ(ierr);
|
|
|
568 |
ierr = VecDestroy(&ip->Bx);CHKERRQ(ierr);
|
| 2370 |
jroman |
569 |
ip->xid = 0;
|
| 2348 |
jroman |
570 |
ip->xstate = 0;
|
|
|
571 |
ierr = IPResetOperationCounters(ip);CHKERRQ(ierr);
|
|
|
572 |
PetscFunctionReturn(0);
|
|
|
573 |
}
|
|
|
574 |
|
|
|
575 |
#undef __FUNCT__
|
| 1302 |
slepc |
576 |
#define __FUNCT__ "IPDestroy"
|
| 2312 |
jroman |
577 |
/*@C
|
| 1345 |
slepc |
578 |
IPDestroy - Destroys IP context that was created with IPCreate().
|
|
|
579 |
|
|
|
580 |
Collective on IP
|
|
|
581 |
|
|
|
582 |
Input Parameter:
|
|
|
583 |
. ip - the inner product context
|
|
|
584 |
|
|
|
585 |
Level: beginner
|
|
|
586 |
|
|
|
587 |
.seealso: IPCreate()
|
|
|
588 |
@*/
|
| 2312 |
jroman |
589 |
PetscErrorCode IPDestroy(IP *ip)
|
| 1302 |
slepc |
590 |
{
|
|
|
591 |
PetscErrorCode ierr;
|
|
|
592 |
|
|
|
593 |
PetscFunctionBegin;
|
| 2312 |
jroman |
594 |
if (!*ip) PetscFunctionReturn(0);
|
|
|
595 |
PetscValidHeaderSpecific(*ip,IP_CLASSID,1);
|
|
|
596 |
if (--((PetscObject)(*ip))->refct > 0) { *ip = 0; PetscFunctionReturn(0); }
|
| 2348 |
jroman |
597 |
ierr = IPReset(*ip);CHKERRQ(ierr);
|
| 2312 |
jroman |
598 |
ierr = PetscHeaderDestroy(ip);CHKERRQ(ierr);
|
| 1302 |
slepc |
599 |
PetscFunctionReturn(0);
|
|
|
600 |
}
|
| 1329 |
slepc |
601 |
|
|
|
602 |
#undef __FUNCT__
|
|
|
603 |
#define __FUNCT__ "IPGetOperationCounters"
|
| 1345 |
slepc |
604 |
/*@
|
|
|
605 |
IPGetOperationCounters - Gets the total number of inner product operations
|
|
|
606 |
made by the IP object.
|
|
|
607 |
|
|
|
608 |
Not Collective
|
|
|
609 |
|
|
|
610 |
Input Parameter:
|
|
|
611 |
. ip - the inner product context
|
|
|
612 |
|
|
|
613 |
Output Parameter:
|
|
|
614 |
. dots - number of inner product operations
|
|
|
615 |
|
|
|
616 |
Level: intermediate
|
|
|
617 |
|
|
|
618 |
.seealso: IPResetOperationCounters()
|
|
|
619 |
@*/
|
| 1509 |
slepc |
620 |
PetscErrorCode IPGetOperationCounters(IP ip,PetscInt *dots)
|
| 1329 |
slepc |
621 |
{
|
|
|
622 |
PetscFunctionBegin;
|
| 2213 |
jroman |
623 |
PetscValidHeaderSpecific(ip,IP_CLASSID,1);
|
| 1329 |
slepc |
624 |
PetscValidPointer(dots,2);
|
|
|
625 |
*dots = ip->innerproducts;
|
|
|
626 |
PetscFunctionReturn(0);
|
|
|
627 |
}
|
|
|
628 |
|
|
|
629 |
#undef __FUNCT__
|
|
|
630 |
#define __FUNCT__ "IPResetOperationCounters"
|
| 1345 |
slepc |
631 |
/*@
|
|
|
632 |
IPResetOperationCounters - Resets the counters for inner product operations
|
|
|
633 |
made by of the IP object.
|
|
|
634 |
|
| 2328 |
jroman |
635 |
Logically Collective on IP
|
| 1345 |
slepc |
636 |
|
|
|
637 |
Input Parameter:
|
|
|
638 |
. ip - the inner product context
|
|
|
639 |
|
|
|
640 |
Level: intermediate
|
|
|
641 |
|
|
|
642 |
.seealso: IPGetOperationCounters()
|
|
|
643 |
@*/
|
| 1329 |
slepc |
644 |
PetscErrorCode IPResetOperationCounters(IP ip)
|
|
|
645 |
{
|
|
|
646 |
PetscFunctionBegin;
|
| 2213 |
jroman |
647 |
PetscValidHeaderSpecific(ip,IP_CLASSID,1);
|
| 1329 |
slepc |
648 |
ip->innerproducts = 0;
|
|
|
649 |
PetscFunctionReturn(0);
|
|
|
650 |
}
|
|
|
651 |
|
| 2373 |
jroman |
652 |
#undef __FUNCT__
|
|
|
653 |
#define __FUNCT__ "IPRegister"
|
|
|
654 |
/*@C
|
|
|
655 |
IPRegister - See IPRegisterDynamic()
|
|
|
656 |
|
|
|
657 |
Level: advanced
|
|
|
658 |
@*/
|
|
|
659 |
PetscErrorCode IPRegister(const char *sname,const char *path,const char *name,PetscErrorCode (*function)(IP))
|
|
|
660 |
{
|
|
|
661 |
PetscErrorCode ierr;
|
| 2374 |
jroman |
662 |
char fullname[PETSC_MAX_PATH_LEN];
|
| 2373 |
jroman |
663 |
|
|
|
664 |
PetscFunctionBegin;
|
|
|
665 |
ierr = PetscFListConcat(path,name,fullname);CHKERRQ(ierr);
|
|
|
666 |
ierr = PetscFListAdd(&IPList,sname,fullname,(void (*)(void))function);CHKERRQ(ierr);
|
|
|
667 |
PetscFunctionReturn(0);
|
|
|
668 |
}
|
|
|
669 |
|
|
|
670 |
#undef __FUNCT__
|
|
|
671 |
#define __FUNCT__ "IPRegisterDestroy"
|
|
|
672 |
/*@
|
|
|
673 |
IPRegisterDestroy - Frees the list of IP methods that were
|
|
|
674 |
registered by IPRegisterDynamic().
|
|
|
675 |
|
|
|
676 |
Not Collective
|
|
|
677 |
|
|
|
678 |
Level: advanced
|
|
|
679 |
|
|
|
680 |
.seealso: IPRegisterDynamic(), IPRegisterAll()
|
|
|
681 |
@*/
|
|
|
682 |
PetscErrorCode IPRegisterDestroy(void)
|
|
|
683 |
{
|
|
|
684 |
PetscErrorCode ierr;
|
|
|
685 |
|
|
|
686 |
PetscFunctionBegin;
|
|
|
687 |
ierr = PetscFListDestroy(&IPList);CHKERRQ(ierr);
|
| 2376 |
jroman |
688 |
IPRegisterAllCalled = PETSC_FALSE;
|
| 2373 |
jroman |
689 |
PetscFunctionReturn(0);
|
|
|
690 |
}
|
|
|
691 |
|
|
|
692 |
EXTERN_C_BEGIN
|
|
|
693 |
extern PetscErrorCode IPCreate_Bilinear(IP);
|
|
|
694 |
#if defined(PETSC_USE_COMPLEX)
|
|
|
695 |
extern PetscErrorCode IPCreate_Sesquilinear(IP);
|
|
|
696 |
#endif
|
| 2746 |
jroman |
697 |
extern PetscErrorCode IPCreate_Indefinite(IP);
|
| 2373 |
jroman |
698 |
EXTERN_C_END
|
|
|
699 |
|
|
|
700 |
#undef __FUNCT__
|
|
|
701 |
#define __FUNCT__ "IPRegisterAll"
|
|
|
702 |
/*@C
|
|
|
703 |
IPRegisterAll - Registers all of the inner products in the IP package.
|
|
|
704 |
|
|
|
705 |
Not Collective
|
|
|
706 |
|
|
|
707 |
Input Parameter:
|
|
|
708 |
. path - the library where the routines are to be found (optional)
|
|
|
709 |
|
|
|
710 |
Level: advanced
|
|
|
711 |
@*/
|
|
|
712 |
PetscErrorCode IPRegisterAll(const char *path)
|
|
|
713 |
{
|
|
|
714 |
PetscErrorCode ierr;
|
|
|
715 |
|
|
|
716 |
PetscFunctionBegin;
|
| 2376 |
jroman |
717 |
IPRegisterAllCalled = PETSC_TRUE;
|
| 2373 |
jroman |
718 |
ierr = IPRegisterDynamic(IPBILINEAR,path,"IPCreate_Bilinear",IPCreate_Bilinear);CHKERRQ(ierr);
|
|
|
719 |
#if defined(PETSC_USE_COMPLEX)
|
|
|
720 |
ierr = IPRegisterDynamic(IPSESQUILINEAR,path,"IPCreate_Sesquilinear",IPCreate_Sesquilinear);CHKERRQ(ierr);
|
|
|
721 |
#endif
|
| 2746 |
jroman |
722 |
ierr = IPRegisterDynamic(IPINDEFINITE,path,"IPCreate_Indefinite",IPCreate_Indefinite);CHKERRQ(ierr);
|
| 2373 |
jroman |
723 |
PetscFunctionReturn(0);
|
|
|
724 |
}
|
|
|
725 |
|