Actual source code: monitor.c

  1: /*
  2:       EPS routines related to monitors.
  3: */
 4:  #include src/eps/epsimpl.h

  8: /*@C
  9:    EPSSetMonitor - Sets an ADDITIONAL function to be called at every 
 10:    iteration to monitor the error estimates for each requested eigenpair.
 11:       
 12:    Collective on EPS

 14:    Input Parameters:
 15: +  eps     - eigensolver context obtained from EPSCreate()
 16: .  monitor - pointer to function (if this is PETSC_NULL, it turns off monitoring
 17: -  mctx    - [optional] context for private data for the
 18:              monitor routine (use PETSC_NULL if no context is desired)

 20:    Calling Sequence of monitor:
 21: $     monitor (EPS eps, int its, int nconv, PetscReal* errest, int nest, void *mctx)

 23: +  eps    - eigensolver context obtained from EPSCreate()
 24: .  its    - iteration number
 25: .  nconv  - number of converged eigenpairs
 26: .  errest - error estimates for each eigenpair
 27: .  nest   - number of error estimates
 28: -  mctx   - optional monitoring context, as set by EPSSetMonitor()

 30:    Options Database Keys:
 31: +    -eps_monitor        - print error estimates at each iteration
 32: -    -eps_cancelmonitors - cancels all monitors that have been hardwired into
 33:       a code by calls to EPSetMonitor(), but does not cancel those set via
 34:       the options database.

 36:    Notes:  
 37:    Several different monitoring routines may be set by calling
 38:    EPSSetMonitor() multiple times; all will be called in the 
 39:    order in which they were set.

 41:    Level: intermediate

 43: .seealso: EPSDefaultEstimatesMonitor(), EPSClearMonitor()
 44: @*/
 45: PetscErrorCode EPSSetMonitor(EPS eps, int (*monitor)(EPS,int,int,PetscScalar*,PetscScalar*,PetscReal*,int,void*), void *mctx)
 46: {
 49:   if (eps->numbermonitors >= MAXEPSMONITORS) {
 50:     SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,"Too many EPS monitors set");
 51:   }
 52:   eps->monitor[eps->numbermonitors]           = monitor;
 53:   eps->monitorcontext[eps->numbermonitors++]  = (void*)mctx;
 54:   return(0);
 55: }

 59: /*@C
 60:    EPSClearMonitor - Clears all monitors for an EPS object.

 62:    Collective on EPS

 64:    Input Parameters:
 65: .  eps - eigensolver context obtained from EPSCreate()

 67:    Options Database Key:
 68: .    -eps_cancelmonitors - Cancels all monitors that have been hardwired 
 69:       into a code by calls to EPSSetMonitor() or EPSSetValuesMonitor(), 
 70:       but does not cancel those set via the options database.

 72:    Level: intermediate

 74: .seealso: EPSSetMonitor(), EPSSetValuesMonitor()
 75: @*/
 76: PetscErrorCode EPSClearMonitor(EPS eps)
 77: {
 80:   eps->numbermonitors = 0;
 81:   return(0);
 82: }

 86: /*@C
 87:    EPSGetMonitorContext - Gets the estimates monitor context, as set by 
 88:    EPSSetMonitor() for the FIRST monitor only.

 90:    Not Collective

 92:    Input Parameter:
 93: .  eps - eigensolver context obtained from EPSCreate()

 95:    Output Parameter:
 96: .  ctx - monitor context

 98:    Level: intermediate

100: .seealso: EPSSetMonitor(), EPSDefaultEstimatesMonitor()
101: @*/
102: PetscErrorCode EPSGetMonitorContext(EPS eps, void **ctx)
103: {
106:   *ctx =      (eps->monitorcontext[0]);
107:   return(0);
108: }

112: /*@C
113:    EPSDefaultEstimatesMonitor - Print the current approximate values and 
114:    error estimates at each iteration of the eigensolver.

116:    Collective on EPS

118:    Input Parameters:
119: +  eps    - eigensolver context
120: .  its    - iteration number
121: .  nconv  - number of converged eigenpairs so far
122: .  eigr   - real part of the eigenvalues
123: .  eigi   - imaginary part of the eigenvalues
124: .  errest - error estimates
125: .  nest   - number of error estimates to display
126: -  dummy  - unused monitor context 

128:    Level: intermediate

130: .seealso: EPSSetMonitor()
131: @*/
132: PetscErrorCode EPSDefaultMonitor(EPS eps,int its,int nconv,PetscScalar *eigr,PetscScalar *eigi,PetscReal *errest,int nest,void *dummy)
133: {
134:   PetscErrorCode ierr;
135:   int            i;
136:   PetscViewer    viewer = (PetscViewer) dummy;

139:   if (!viewer) viewer = PETSC_VIEWER_STDOUT_(eps->comm);
140:   PetscViewerASCIIPrintf(viewer,"%3d EPS nconv=%d Values (Errors)",its,nconv);
141:   for (i=0;i<nest;i++) {
142: #if defined(PETSC_USE_COMPLEX)
143:     PetscViewerASCIIPrintf(viewer," %g%+gi",PetscRealPart(eigr[i]),PetscImaginaryPart(eigr[i]));
144: #else
145:     PetscViewerASCIIPrintf(viewer," %g",eigr[i]);
146:     if (eigi[i]!=0.0) { PetscViewerASCIIPrintf(viewer,"%+gi",eigi[i]); }
147: #endif
148:     PetscViewerASCIIPrintf(viewer," (%10.8e)",errest[i]);
149:   }
150:   PetscViewerASCIIPrintf(viewer,"\n");
151:   return(0);
152: }