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
525 dsic.upv.es!antodo 1
/*
545 dsic.upv.es!jroman 2
      EPS routines related to monitors.
1376 slepc 3
 
4
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
5
      SLEPc - Scalable Library for Eigenvalue Problem Computations
6
      Copyright (c) 2002-2007, Universidad Politecnica de Valencia, Spain
7
 
8
      This file is part of SLEPc. See the README file for conditions of use
9
      and additional information.
10
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
525 dsic.upv.es!antodo 11
*/
1376 slepc 12
 
525 dsic.upv.es!antodo 13
#include "src/eps/epsimpl.h"   /*I "slepceps.h" I*/
14
 
15
#undef __FUNCT__  
1331 slepc 16
#define __FUNCT__ "EPSMonitorSet"
525 dsic.upv.es!antodo 17
/*@C
1331 slepc 18
   EPSMonitorSet - Sets an ADDITIONAL function to be called at every
525 dsic.upv.es!antodo 19
   iteration to monitor the error estimates for each requested eigenpair.
20
 
21
   Collective on EPS
22
 
23
   Input Parameters:
24
+  eps     - eigensolver context obtained from EPSCreate()
1021 slepc 25
.  monitor - pointer to function (if this is PETSC_NULL, it turns off monitoring)
1287 slepc 26
.  mctx    - [optional] context for private data for the
525 dsic.upv.es!antodo 27
             monitor routine (use PETSC_NULL if no context is desired)
1287 slepc 28
-  monitordestroy - [optional] routine that frees monitor context
29
          (may be PETSC_NULL)
525 dsic.upv.es!antodo 30
 
31
   Calling Sequence of monitor:
617 dsic.upv.es!antodo 32
$     monitor (EPS eps, int its, int nconv, PetscScalar *eigr, PetscScalar *eigi, PetscReal* errest, int nest, void *mctx)
525 dsic.upv.es!antodo 33
 
34
+  eps    - eigensolver context obtained from EPSCreate()
35
.  its    - iteration number
36
.  nconv  - number of converged eigenpairs
617 dsic.upv.es!antodo 37
.  eigr   - real part of the eigenvalues
38
.  eigi   - imaginary part of the eigenvalues
663 dsic.upv.es!antodo 39
.  errest - relative error estimates for each eigenpair
525 dsic.upv.es!antodo 40
.  nest   - number of error estimates
1331 slepc 41
-  mctx   - optional monitoring context, as set by EPSMonitorSet()
525 dsic.upv.es!antodo 42
 
43
   Options Database Keys:
44
+    -eps_monitor        - print error estimates at each iteration
1331 slepc 45
.    -eps_monitor_draw   - sets line graph monitor
46
-    -eps_monitor_cancel - cancels all monitors that have been hardwired into
47
      a code by calls to EPSMonitorSet(), but does not cancel those set via
525 dsic.upv.es!antodo 48
      the options database.
49
 
50
   Notes:  
51
   Several different monitoring routines may be set by calling
1331 slepc 52
   EPSMonitorSet() multiple times; all will be called in the
525 dsic.upv.es!antodo 53
   order in which they were set.
54
 
55
   Level: intermediate
56
 
1331 slepc 57
.seealso: EPSMonitorDefault(), EPSMonitorCancel()
525 dsic.upv.es!antodo 58
@*/
1331 slepc 59
PetscErrorCode EPSMonitorSet(EPS eps,PetscErrorCode (*monitor)(EPS,int,int,PetscScalar*,PetscScalar*,PetscReal*,int,void*),
1288 slepc 60
                             void *mctx,PetscErrorCode (*monitordestroy)(void*))
525 dsic.upv.es!antodo 61
{
62
  PetscFunctionBegin;
63
  PetscValidHeaderSpecific(eps,EPS_COOKIE,1);
64
  if (eps->numbermonitors >= MAXEPSMONITORS) {
65
    SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,"Too many EPS monitors set");
66
  }
67
  eps->monitor[eps->numbermonitors]           = monitor;
1287 slepc 68
  eps->monitorcontext[eps->numbermonitors]    = (void*)mctx;
69
  eps->monitordestroy[eps->numbermonitors++]  = monitordestroy;
525 dsic.upv.es!antodo 70
  PetscFunctionReturn(0);
71
}
72
 
73
#undef __FUNCT__  
1331 slepc 74
#define __FUNCT__ "EPSMonitorCancel"
1021 slepc 75
/*@
1331 slepc 76
   EPSMonitorCancel - Clears all monitors for an EPS object.
525 dsic.upv.es!antodo 77
 
78
   Collective on EPS
79
 
80
   Input Parameters:
81
.  eps - eigensolver context obtained from EPSCreate()
82
 
83
   Options Database Key:
1331 slepc 84
.    -eps_monitor_cancel - Cancels all monitors that have been hardwired
85
      into a code by calls to EPSMonitorSet(),
525 dsic.upv.es!antodo 86
      but does not cancel those set via the options database.
87
 
88
   Level: intermediate
89
 
1331 slepc 90
.seealso: EPSMonitorSet()
525 dsic.upv.es!antodo 91
@*/
1331 slepc 92
PetscErrorCode EPSMonitorCancel(EPS eps)
525 dsic.upv.es!antodo 93
{
1287 slepc 94
  PetscErrorCode ierr;
95
  PetscInt       i;
96
 
525 dsic.upv.es!antodo 97
  PetscFunctionBegin;
98
  PetscValidHeaderSpecific(eps,EPS_COOKIE,1);
1287 slepc 99
  for (i=0; i<eps->numbermonitors; i++) {
100
    if (eps->monitordestroy[i]) {
101
      ierr = (*eps->monitordestroy[i])(eps->monitorcontext[i]);CHKERRQ(ierr);
102
    }
103
  }
525 dsic.upv.es!antodo 104
  eps->numbermonitors = 0;
105
  PetscFunctionReturn(0);
106
}
107
 
108
#undef __FUNCT__  
109
#define __FUNCT__ "EPSGetMonitorContext"
110
/*@C
1021 slepc 111
   EPSGetMonitorContext - Gets the monitor context, as set by
525 dsic.upv.es!antodo 112
   EPSSetMonitor() for the FIRST monitor only.
113
 
114
   Not Collective
115
 
116
   Input Parameter:
117
.  eps - eigensolver context obtained from EPSCreate()
118
 
119
   Output Parameter:
120
.  ctx - monitor context
121
 
122
   Level: intermediate
123
 
1021 slepc 124
.seealso: EPSSetMonitor(), EPSDefaultMonitor()
525 dsic.upv.es!antodo 125
@*/
126
PetscErrorCode EPSGetMonitorContext(EPS eps, void **ctx)
127
{
128
  PetscFunctionBegin;
129
  PetscValidHeaderSpecific(eps,EPS_COOKIE,1);
130
  *ctx =      (eps->monitorcontext[0]);
131
  PetscFunctionReturn(0);
132
}
133
 
134
#undef __FUNCT__  
1331 slepc 135
#define __FUNCT__ "EPSMonitorDefault"
525 dsic.upv.es!antodo 136
/*@C
1331 slepc 137
   EPSMonitorDefault - Print the current approximate values and
525 dsic.upv.es!antodo 138
   error estimates at each iteration of the eigensolver.
139
 
140
   Collective on EPS
141
 
142
   Input Parameters:
143
+  eps    - eigensolver context
144
.  its    - iteration number
145
.  nconv  - number of converged eigenpairs so far
146
.  eigr   - real part of the eigenvalues
147
.  eigi   - imaginary part of the eigenvalues
148
.  errest - error estimates
149
.  nest   - number of error estimates to display
150
-  dummy  - unused monitor context
151
 
152
   Level: intermediate
153
 
1331 slepc 154
.seealso: EPSMonitorSet()
525 dsic.upv.es!antodo 155
@*/
1331 slepc 156
PetscErrorCode EPSMonitorDefault(EPS eps,int its,int nconv,PetscScalar *eigr,PetscScalar *eigi,PetscReal *errest,int nest,void *dummy)
525 dsic.upv.es!antodo 157
{
158
  PetscErrorCode ierr;
159
  int            i;
160
  PetscViewer    viewer = (PetscViewer) dummy;
161
 
162
  PetscFunctionBegin;
1220 slepc 163
  if (its) {
1422 slepc 164
    if (!viewer) viewer = PETSC_VIEWER_STDOUT_(((PetscObject)eps)->comm);
1220 slepc 165
    ierr = PetscViewerASCIIPrintf(viewer,"%3d EPS nconv=%d Values (Errors)",its,nconv);CHKERRQ(ierr);
166
    for (i=0;i<nest;i++) {
525 dsic.upv.es!antodo 167
#if defined(PETSC_USE_COMPLEX)
1220 slepc 168
      ierr = PetscViewerASCIIPrintf(viewer," %g%+gi",PetscRealPart(eigr[i]),PetscImaginaryPart(eigr[i]));CHKERRQ(ierr);
525 dsic.upv.es!antodo 169
#else
1220 slepc 170
      ierr = PetscViewerASCIIPrintf(viewer," %g",eigr[i]);CHKERRQ(ierr);
171
      if (eigi[i]!=0.0) { ierr = PetscViewerASCIIPrintf(viewer,"%+gi",eigi[i]);CHKERRQ(ierr); }
525 dsic.upv.es!antodo 172
#endif
1220 slepc 173
      ierr = PetscViewerASCIIPrintf(viewer," (%10.8e)",errest[i]);CHKERRQ(ierr);
174
    }
175
    ierr = PetscViewerASCIIPrintf(viewer,"\n");CHKERRQ(ierr);
525 dsic.upv.es!antodo 176
  }
177
  PetscFunctionReturn(0);
178
}
623 dsic.upv.es!antodo 179
 
180
#undef __FUNCT__  
1331 slepc 181
#define __FUNCT__ "EPSMonitorLG"
182
PetscErrorCode EPSMonitorLG(EPS eps,int its,int nconv,PetscScalar *eigr,PetscScalar *eigi,PetscReal *errest,int nest,void *monctx)
623 dsic.upv.es!antodo 183
{
626 dsic.upv.es!antodo 184
  PetscViewer    viewer = (PetscViewer) monctx;
185
  PetscDraw      draw;
186
  PetscDrawLG    lg;
623 dsic.upv.es!antodo 187
  PetscErrorCode ierr;
188
  PetscReal      *x,*y;
189
  int            i,n = eps->nev;
626 dsic.upv.es!antodo 190
#if !defined(PETSC_USE_COMPLEX)
1004 slepc 191
  int            p;
626 dsic.upv.es!antodo 192
  PetscDraw      draw1;
193
  PetscDrawLG    lg1;
194
#endif
623 dsic.upv.es!antodo 195
 
196
  PetscFunctionBegin;
197
 
1422 slepc 198
  if (!viewer) { viewer = PETSC_VIEWER_DRAW_(((PetscObject)eps)->comm); }
626 dsic.upv.es!antodo 199
 
200
  ierr = PetscViewerDrawGetDraw(viewer,0,&draw);CHKERRQ(ierr);
201
  ierr = PetscViewerDrawGetDrawLG(viewer,0,&lg);CHKERRQ(ierr);
202
  if (!its) {
628 dsic.upv.es!antodo 203
    ierr = PetscDrawSetTitle(draw,"Error estimates");CHKERRQ(ierr);
626 dsic.upv.es!antodo 204
    ierr = PetscDrawSetDoubleBuffer(draw);CHKERRQ(ierr);
205
    ierr = PetscDrawLGSetDimension(lg,n);CHKERRQ(ierr);
206
    ierr = PetscDrawLGReset(lg);CHKERRQ(ierr);
207
    ierr = PetscDrawLGSetLimits(lg,0,1.0,log10(eps->tol)-2,0.0);CHKERRQ(ierr);
208
  }
209
 
210
#if !defined(PETSC_USE_COMPLEX)
211
  if (eps->ishermitian) {
212
    ierr = PetscViewerDrawGetDraw(viewer,1,&draw1);CHKERRQ(ierr);
213
    ierr = PetscViewerDrawGetDrawLG(viewer,1,&lg1);CHKERRQ(ierr);
623 dsic.upv.es!antodo 214
    if (!its) {
628 dsic.upv.es!antodo 215
      ierr = PetscDrawSetTitle(draw1,"Approximate eigenvalues");CHKERRQ(ierr);
626 dsic.upv.es!antodo 216
      ierr = PetscDrawSetDoubleBuffer(draw1);CHKERRQ(ierr);
217
      ierr = PetscDrawLGSetDimension(lg1,n);CHKERRQ(ierr);
218
      ierr = PetscDrawLGReset(lg1);CHKERRQ(ierr);
219
      ierr = PetscDrawLGSetLimits(lg1,0,1.0,1.e20,-1.e20);CHKERRQ(ierr);
623 dsic.upv.es!antodo 220
    }
221
  }
626 dsic.upv.es!antodo 222
#endif
623 dsic.upv.es!antodo 223
 
224
  ierr = PetscMalloc(sizeof(PetscReal)*n,&x);CHKERRQ(ierr);
225
  ierr = PetscMalloc(sizeof(PetscReal)*n,&y);CHKERRQ(ierr);
226
  for (i=0;i<n;i++) {
227
    x[i] = (PetscReal) its;
228
    if (errest[i] > 0.0) y[i] = log10(errest[i]); else y[i] = 0.0;
229
  }
230
  ierr = PetscDrawLGAddPoint(lg,x,y);CHKERRQ(ierr);
626 dsic.upv.es!antodo 231
#if !defined(PETSC_USE_COMPLEX)
232
  if (eps->ishermitian) {
233
    ierr = PetscDrawLGAddPoint(lg1,x,eps->eigr);CHKERRQ(ierr);
1004 slepc 234
    ierr = PetscDrawGetPause(draw1,&p);CHKERRQ(ierr);
626 dsic.upv.es!antodo 235
    ierr = PetscDrawSetPause(draw1,0);CHKERRQ(ierr);    
236
    ierr = PetscDrawLGDraw(lg1);CHKERRQ(ierr);
1004 slepc 237
    ierr = PetscDrawSetPause(draw1,p);CHKERRQ(ierr);    
626 dsic.upv.es!antodo 238
  }
239
#endif  
705 dsic.upv.es!antodo 240
  ierr = PetscDrawLGDraw(lg);CHKERRQ(ierr);
623 dsic.upv.es!antodo 241
  ierr = PetscFree(x);CHKERRQ(ierr);
242
  ierr = PetscFree(y);CHKERRQ(ierr);  
243
  PetscFunctionReturn(0);
244
}
1021 slepc 245