Subversion Repositories slepc-dev

Rev

Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1302 slepc 1
/*
2
     Basic routines
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
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1302 slepc 22
*/
1376 slepc 23
 
1521 slepc 24
#include "private/ipimpl.h"      /*I "slepcip.h" I*/
1302 slepc 25
 
26
PetscCookie IP_COOKIE = 0;
1493 slepc 27
PetscLogEvent IP_InnerProduct = 0, IP_Orthogonalize = 0, IP_ApplyMatrix = 0;
1302 slepc 28
 
29
#undef __FUNCT__  
1329 slepc 30
#define __FUNCT__ "IPInitializePackage"
1345 slepc 31
/*@C
32
  IPInitializePackage - This function initializes everything in the IP package. It is called
33
  from PetscDLLibraryRegister() when using dynamic libraries, and on the first call to IPCreate()
34
  when using static libraries.
35
 
36
  Input Parameter:
37
  path - The dynamic library path, or PETSC_NULL
38
 
39
  Level: developer
40
 
41
.seealso: SlepcInitialize()
42
@*/
1302 slepc 43
PetscErrorCode IPInitializePackage(char *path)
44
{
45
  static PetscTruth initialized = PETSC_FALSE;
46
  char              logList[256];
47
  char              *className;
48
  PetscTruth        opt;
49
  PetscErrorCode    ierr;
50
 
51
  PetscFunctionBegin;
52
  if (initialized) PetscFunctionReturn(0);
53
  initialized = PETSC_TRUE;
54
  /* Register Classes */
1493 slepc 55
  ierr = PetscCookieRegister("Inner product",&IP_COOKIE);CHKERRQ(ierr);
1302 slepc 56
  /* Register Events */
1493 slepc 57
  ierr = PetscLogEventRegister("IPOrthogonalize",IP_COOKIE,&IP_Orthogonalize); CHKERRQ(ierr);
58
  ierr = PetscLogEventRegister("IPInnerProduct",IP_COOKIE,&IP_InnerProduct); CHKERRQ(ierr);
59
  ierr = PetscLogEventRegister("IPApplyMatrix",IP_COOKIE,&IP_ApplyMatrix); CHKERRQ(ierr);
1302 slepc 60
  /* Process info exclusions */
61
  ierr = PetscOptionsGetString(PETSC_NULL, "-log_info_exclude", logList, 256, &opt);CHKERRQ(ierr);
62
  if (opt) {
63
    ierr = PetscStrstr(logList, "ip", &className);CHKERRQ(ierr);
64
    if (className) {
65
      ierr = PetscInfoDeactivateClass(IP_COOKIE);CHKERRQ(ierr);
66
    }
67
  }
68
  /* Process summary exclusions */
69
  ierr = PetscOptionsGetString(PETSC_NULL, "-log_summary_exclude", logList, 256, &opt);CHKERRQ(ierr);
70
  if (opt) {
71
    ierr = PetscStrstr(logList, "ip", &className);CHKERRQ(ierr);
72
    if (className) {
73
      ierr = PetscLogEventDeactivateClass(IP_COOKIE);CHKERRQ(ierr);
74
    }
75
  }
76
  PetscFunctionReturn(0);
77
}
78
 
79
#undef __FUNCT__  
80
#define __FUNCT__ "IPCreate"
1345 slepc 81
/*@C
82
   IPCreate - Creates an IP context.
83
 
84
   Collective on MPI_Comm
85
 
86
   Input Parameter:
87
.  comm - MPI communicator
88
 
89
   Output Parameter:
1349 slepc 90
.  newip - location to put the IP context
1345 slepc 91
 
92
   Level: beginner
93
 
1349 slepc 94
   Note:
95
   IP objects are not intended for normal users but only for
96
   advanced user that for instance implement their own solvers.
97
 
1345 slepc 98
.seealso: IPDestroy(), IP
99
@*/
1302 slepc 100
PetscErrorCode IPCreate(MPI_Comm comm,IP *newip)
101
{
1345 slepc 102
  PetscErrorCode ierr;
1302 slepc 103
  IP ip;
104
 
105
  PetscFunctionBegin;
106
  PetscValidPointer(newip,2);
1537 slepc 107
  ierr = PetscHeaderCreate(ip,_p_IP,int,IP_COOKIE,-1,"IP",comm,IPDestroy,IPView);CHKERRQ(ierr);
1302 slepc 108
  *newip            = ip;
1940 jroman 109
  ip->orthog_type   = IP_ORTH_CGS;
1302 slepc 110
  ip->orthog_ref    = IP_ORTH_REFINE_IFNEEDED;
111
  ip->orthog_eta    = 0.7071;
1940 jroman 112
  ip->bilinear_form = IP_INNER_HERMITIAN;
1302 slepc 113
  ip->innerproducts = 0;
1329 slepc 114
  ip->matrix        = PETSC_NULL;
1361 slepc 115
  ip->Bx            = PETSC_NULL;
116
  ip->xid           = 0;
117
  ip->xstate        = 0;
1345 slepc 118
 
119
  ierr = PetscPublishAll(ip);CHKERRQ(ierr);
1302 slepc 120
  PetscFunctionReturn(0);
121
}
122
 
123
#undef __FUNCT__  
1316 slepc 124
#define __FUNCT__ "IPSetOptionsPrefix"
1345 slepc 125
/*@C
126
   IPSetOptionsPrefix - Sets the prefix used for searching for all
127
   IP options in the database.
128
 
129
   Collective on IP
130
 
131
   Input Parameters:
132
+  ip - the innerproduct context
133
-  prefix - the prefix string to prepend to all IP option requests
134
 
135
   Notes:
136
   A hyphen (-) must NOT be given at the beginning of the prefix name.
137
   The first character of all runtime options is AUTOMATICALLY the
138
   hyphen.
139
 
140
   Level: advanced
141
 
142
.seealso: IPAppendOptionsPrefix()
143
@*/
1316 slepc 144
PetscErrorCode IPSetOptionsPrefix(IP ip,const char *prefix)
145
{
146
  PetscErrorCode ierr;
147
  PetscFunctionBegin;
148
  PetscValidHeaderSpecific(ip,IP_COOKIE,1);
149
  ierr = PetscObjectSetOptionsPrefix((PetscObject)ip,prefix);CHKERRQ(ierr);
150
  PetscFunctionReturn(0);
151
}
152
 
153
#undef __FUNCT__  
1302 slepc 154
#define __FUNCT__ "IPAppendOptionsPrefix"
1345 slepc 155
/*@C
156
   IPAppendOptionsPrefix - Appends to the prefix used for searching for all
157
   IP options in the database.
158
 
159
   Collective on IP
160
 
161
   Input Parameters:
162
+  ip - the innerproduct context
163
-  prefix - the prefix string to prepend to all IP option requests
164
 
165
   Notes:
166
   A hyphen (-) must NOT be given at the beginning of the prefix name.
167
   The first character of all runtime options is AUTOMATICALLY the hyphen.
168
 
169
   Level: advanced
170
 
171
.seealso: IPSetOptionsPrefix()
172
@*/
1302 slepc 173
PetscErrorCode IPAppendOptionsPrefix(IP ip,const char *prefix)
174
{
175
  PetscErrorCode ierr;
176
  PetscFunctionBegin;
177
  PetscValidHeaderSpecific(ip,IP_COOKIE,1);
178
  ierr = PetscObjectAppendOptionsPrefix((PetscObject)ip,prefix);CHKERRQ(ierr);
179
  PetscFunctionReturn(0);
180
}
181
 
1518 slepc 182
#undef __FUNCT__
183
#define __FUNCT__ "IPGetOptionsPrefix"
184
/*@C
185
   IPGetOptionsPrefix - Gets the prefix used for searching for all
186
   IP options in the database.
187
 
188
   Not Collective
189
 
190
   Input Parameters:
191
.  ip - the innerproduct context
192
 
193
   Output Parameters:
194
.  prefix - pointer to the prefix string used is returned
195
 
196
   Notes: On the fortran side, the user should pass in a string 'prefix' of
197
   sufficient length to hold the prefix.
198
 
199
   Level: advanced
200
 
201
.seealso: IPSetOptionsPrefix(), IPAppendOptionsPrefix()
202
@*/
203
PetscErrorCode IPGetOptionsPrefix(IP ip,const char *prefix[])
204
{
205
 PetscErrorCode ierr;
206
 PetscFunctionBegin;
207
 PetscValidHeaderSpecific(ip,IP_COOKIE,1);
208
 PetscValidPointer(prefix,2);
209
 ierr = PetscObjectGetOptionsPrefix((PetscObject)ip, prefix);CHKERRQ(ierr);
210
 PetscFunctionReturn(0);
211
}
212
 
213
 
1302 slepc 214
#undef __FUNCT__  
215
#define __FUNCT__ "IPSetFromOptions"
1345 slepc 216
/*@
217
   IPSetFromOptions - Sets IP options from the options database.
218
 
219
   Collective on IP
220
 
221
   Input Parameters:
222
.  ip - the innerproduct context
223
 
224
   Notes:  
225
   To see all options, run your program with the -help option.
226
 
227
   Level: beginner
228
 
229
.seealso:
230
@*/
1302 slepc 231
PetscErrorCode IPSetFromOptions(IP ip)
232
{
233
  PetscErrorCode ierr;
1858 antodo 234
  const char     *orth_list[2] = { "mgs" , "cgs" };
1302 slepc 235
  const char     *ref_list[3] = { "never" , "ifneeded", "always" };
236
  PetscReal      r;
237
  PetscInt       i,j;
238
 
239
  PetscFunctionBegin;
240
  PetscValidHeaderSpecific(ip,IP_COOKIE,1);
1422 slepc 241
  ierr = PetscOptionsBegin(((PetscObject)ip)->comm,((PetscObject)ip)->prefix,"Inner Product (IP) Options","IP");CHKERRQ(ierr);
1302 slepc 242
  i = ip->orthog_type;
1858 antodo 243
  ierr = PetscOptionsEList("-orthog_type","Orthogonalization method","IPSetOrthogonalization",orth_list,2,orth_list[i],&i,PETSC_NULL);CHKERRQ(ierr);
1302 slepc 244
  j = ip->orthog_ref;
245
  ierr = PetscOptionsEList("-orthog_refinement","Iterative refinement mode during orthogonalization","IPSetOrthogonalization",ref_list,3,ref_list[j],&j,PETSC_NULL);CHKERRQ(ierr);
246
  r = ip->orthog_eta;
247
  ierr = PetscOptionsReal("-orthog_eta","Parameter of iterative refinement during orthogonalization","IPSetOrthogonalization",r,&r,PETSC_NULL);CHKERRQ(ierr);
248
  ierr = IPSetOrthogonalization(ip,(IPOrthogonalizationType)i,(IPOrthogonalizationRefinementType)j,r);CHKERRQ(ierr);
249
  ierr = PetscOptionsEnd();CHKERRQ(ierr);
250
  PetscFunctionReturn(0);
251
}
252
 
253
#undef __FUNCT__  
254
#define __FUNCT__ "IPSetOrthogonalization"
1345 slepc 255
/*@
256
   IPSetOrthogonalization - Specifies the type of orthogonalization technique
257
   to be used (classical or modified Gram-Schmidt with or without refinement).
258
 
259
   Collective on IP
260
 
261
   Input Parameters:
262
+  ip         - the innerproduct context
263
.  type       - the type of orthogonalization technique
264
.  refinement - type of refinement
265
-  eta        - parameter for selective refinement
266
 
267
   Options Database Keys:
268
+  -orthog_type <type> -  Where <type> is cgs for Classical Gram-Schmidt
269
                              orthogonalization (default)
270
                              or mgs for Modified Gram-Schmidt orthogonalization
271
.  -orthog_refinement <type> -  Where <type> is one of never, ifneeded
272
                              (default) or always
273
-  -orthog_eta <eta> -  For setting the value of eta
274
 
275
   Notes:  
276
   The default settings work well for most problems.
277
 
278
   The parameter eta should be a real value between 0 and 1 (or PETSC_DEFAULT).
279
   The value of eta is used only when the refinement type is "ifneeded".
280
 
281
   When using several processors, MGS is likely to result in bad scalability.
282
 
283
   Level: advanced
284
 
1364 slepc 285
.seealso: IPOrthogonalize(), IPGetOrthogonalization(), IPOrthogonalizationType,
286
          IPOrthogonalizationRefinementType
1345 slepc 287
@*/
1302 slepc 288
PetscErrorCode IPSetOrthogonalization(IP ip,IPOrthogonalizationType type, IPOrthogonalizationRefinementType refinement, PetscReal eta)
289
{
290
  PetscFunctionBegin;
291
  PetscValidHeaderSpecific(ip,IP_COOKIE,1);
292
  switch (type) {
1940 jroman 293
    case IP_ORTH_CGS:
294
    case IP_ORTH_MGS:
1302 slepc 295
      ip->orthog_type = type;
296
      break;
297
    default:
298
      SETERRQ(PETSC_ERR_ARG_WRONG,"Unknown orthogonalization type");
299
  }
300
  switch (refinement) {
301
    case IP_ORTH_REFINE_NEVER:
302
    case IP_ORTH_REFINE_IFNEEDED:
303
    case IP_ORTH_REFINE_ALWAYS:
304
      ip->orthog_ref = refinement;
305
      break;
306
    default:
307
      SETERRQ(PETSC_ERR_ARG_WRONG,"Unknown refinement type");
308
  }
309
  if (eta == PETSC_DEFAULT) {
310
    ip->orthog_eta = 0.7071;
311
  } else {
312
    if (eta <= 0.0 || eta > 1.0) SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,"Invalid eta value");    
313
    ip->orthog_eta = eta;
314
  }
315
  PetscFunctionReturn(0);
316
}
317
 
318
#undef __FUNCT__  
1345 slepc 319
#define __FUNCT__ "IPGetOrthogonalization"
320
/*@C
321
   IPGetOrthogonalization - Gets the orthogonalization settings from the
322
   IP object.
323
 
324
   Not Collective
325
 
326
   Input Parameter:
327
.  ip - inner product context
328
 
329
   Output Parameter:
330
+  type       - type of orthogonalization technique
331
.  refinement - type of refinement
332
-  eta        - parameter for selective refinement
333
 
334
   Level: advanced
335
 
1364 slepc 336
.seealso: IPOrthogonalize(), IPSetOrthogonalization(), IPOrthogonalizationType,
337
          IPOrthogonalizationRefinementType
1345 slepc 338
@*/
339
PetscErrorCode IPGetOrthogonalization(IP ip,IPOrthogonalizationType *type,IPOrthogonalizationRefinementType *refinement, PetscReal *eta)
340
{
341
  PetscFunctionBegin;
342
  PetscValidHeaderSpecific(ip,IP_COOKIE,1);
343
  if (type) *type = ip->orthog_type;
344
  if (refinement) *refinement = ip->orthog_ref;
345
  if (eta) *eta = ip->orthog_eta;
346
  PetscFunctionReturn(0);
347
}
348
 
349
#undef __FUNCT__  
1302 slepc 350
#define __FUNCT__ "IPView"
1345 slepc 351
/*@C
352
   IPView - Prints the IP data structure.
353
 
354
   Collective on IP
355
 
356
   Input Parameters:
357
+  ip - the innerproduct context
358
-  viewer - optional visualization context
359
 
360
   Note:
361
   The available visualization contexts include
362
+     PETSC_VIEWER_STDOUT_SELF - standard output (default)
363
-     PETSC_VIEWER_STDOUT_WORLD - synchronized standard
364
         output where only the first processor opens
365
         the file.  All other processors send their
366
         data to the first processor to print.
367
 
368
   The user can open an alternative visualization context with
369
   PetscViewerASCIIOpen() - output to a specified file.
370
 
371
   Level: beginner
372
 
373
.seealso: IPView(), EPSView(), SVDView(), PetscViewerASCIIOpen()
374
@*/
1302 slepc 375
PetscErrorCode IPView(IP ip,PetscViewer viewer)
376
{
377
  PetscErrorCode ierr;
378
  PetscTruth     isascii;
379
 
380
  PetscFunctionBegin;
381
  PetscValidHeaderSpecific(ip,IP_COOKIE,1);
1422 slepc 382
  if (!viewer) viewer = PETSC_VIEWER_STDOUT_(((PetscObject)ip)->comm);
1302 slepc 383
  PetscValidHeaderSpecific(viewer,PETSC_VIEWER_COOKIE,2);
384
  PetscCheckSameComm(ip,1,viewer,2);
385
 
386
  ierr = PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&isascii);CHKERRQ(ierr);
387
  if (isascii) {
388
    ierr = PetscViewerASCIIPrintf(viewer,"IP Object:\n");CHKERRQ(ierr);
389
    ierr = PetscViewerASCIIPrintf(viewer,"  orthogonalization method: ");CHKERRQ(ierr);
390
    switch (ip->orthog_type) {
1940 jroman 391
      case IP_ORTH_MGS:
1302 slepc 392
        ierr = PetscViewerASCIIPrintf(viewer,"modified Gram-Schmidt\n");CHKERRQ(ierr);
393
        break;
1940 jroman 394
      case IP_ORTH_CGS:
1302 slepc 395
        ierr = PetscViewerASCIIPrintf(viewer,"classical Gram-Schmidt\n");CHKERRQ(ierr);
396
        break;
397
      default: SETERRQ(1,"Wrong value of ip->orth_type");
398
    }
399
    ierr = PetscViewerASCIIPrintf(viewer,"  orthogonalization refinement: ");CHKERRQ(ierr);
400
    switch (ip->orthog_ref) {
401
      case IP_ORTH_REFINE_NEVER:
402
        ierr = PetscViewerASCIIPrintf(viewer,"never\n");CHKERRQ(ierr);
403
        break;
404
      case IP_ORTH_REFINE_IFNEEDED:
405
        ierr = PetscViewerASCIIPrintf(viewer,"if needed (eta: %f)\n",ip->orthog_eta);CHKERRQ(ierr);
406
        break;
407
      case IP_ORTH_REFINE_ALWAYS:
408
        ierr = PetscViewerASCIIPrintf(viewer,"always\n");CHKERRQ(ierr);
409
        break;
410
      default: SETERRQ(1,"Wrong value of ip->orth_ref");
411
    }
412
  } else {
413
    SETERRQ1(1,"Viewer type %s not supported for IP",((PetscObject)viewer)->type_name);
414
  }
415
  PetscFunctionReturn(0);
416
}
417
 
418
#undef __FUNCT__  
419
#define __FUNCT__ "IPDestroy"
1345 slepc 420
/*@
421
   IPDestroy - Destroys IP context that was created with IPCreate().
422
 
423
   Collective on IP
424
 
425
   Input Parameter:
426
.  ip - the inner product context
427
 
428
   Level: beginner
429
 
430
.seealso: IPCreate()
431
@*/
1302 slepc 432
PetscErrorCode IPDestroy(IP ip)
433
{
434
  PetscErrorCode ierr;
435
 
436
  PetscFunctionBegin;
437
  PetscValidHeaderSpecific(ip,IP_COOKIE,1);
1572 slepc 438
  if (--((PetscObject)ip)->refct > 0) PetscFunctionReturn(0);
439
 
1329 slepc 440
  if (ip->matrix) { ierr = MatDestroy(ip->matrix);CHKERRQ(ierr); }
1361 slepc 441
  if (ip->Bx) { ierr = VecDestroy(ip->Bx);CHKERRQ(ierr); }
1572 slepc 442
  ierr = PetscHeaderDestroy(ip);CHKERRQ(ierr);
1302 slepc 443
  PetscFunctionReturn(0);
444
}
1329 slepc 445
 
446
#undef __FUNCT__  
447
#define __FUNCT__ "IPGetOperationCounters"
1345 slepc 448
/*@
449
   IPGetOperationCounters - Gets the total number of inner product operations
450
   made by the IP object.
451
 
452
   Not Collective
453
 
454
   Input Parameter:
455
.  ip - the inner product context
456
 
457
   Output Parameter:
458
.  dots - number of inner product operations
459
 
460
   Level: intermediate
461
 
462
.seealso: IPResetOperationCounters()
463
@*/
1509 slepc 464
PetscErrorCode IPGetOperationCounters(IP ip,PetscInt *dots)
1329 slepc 465
{
466
  PetscFunctionBegin;
467
  PetscValidHeaderSpecific(ip,IP_COOKIE,1);
468
  PetscValidPointer(dots,2);
469
  *dots = ip->innerproducts;
470
  PetscFunctionReturn(0);
471
}
472
 
473
#undef __FUNCT__  
474
#define __FUNCT__ "IPResetOperationCounters"
1345 slepc 475
/*@
476
   IPResetOperationCounters - Resets the counters for inner product operations
477
   made by of the IP object.
478
 
479
   Collective on IP
480
 
481
   Input Parameter:
482
.  ip - the inner product context
483
 
484
   Level: intermediate
485
 
486
.seealso: IPGetOperationCounters()
487
@*/
1329 slepc 488
PetscErrorCode IPResetOperationCounters(IP ip)
489
{
490
  PetscFunctionBegin;
491
  PetscValidHeaderSpecific(ip,IP_COOKIE,1);
492
  ip->innerproducts = 0;
493
  PetscFunctionReturn(0);
494
}
495