Actual source code: xmon.c

  1: /*$Id: xmon.c,v 1.50 2001/04/10 19:36:24 bsmith Exp $*/

 3:  #include src/sles/ksp/kspimpl.h

  5: /*@C
  6:    KSPLGMonitorCreate - Creates a line graph context for use with 
  7:    KSP to monitor convergence of preconditioned residual norms.

  9:    Collective on KSP

 11:    Input Parameters:
 12: +  host - the X display to open, or null for the local machine
 13: .  label - the title to put in the title bar
 14: .  x, y - the screen coordinates of the upper left coordinate of
 15:           the window
 16: -  m, n - the screen width and height in pixels

 18:    Output Parameter:
 19: .  draw - the drawing context

 21:    Options Database Key:
 22: .  -ksp_xmonitor - Sets line graph monitor

 24:    Notes: 
 25:    Use KSPLGMonitorDestroy() to destroy this line graph; do not use PetscDrawLGDestroy().

 27:    Level: intermediate

 29: .keywords: KSP, monitor, line graph, residual, create

 31: .seealso: KSPLGMonitorDestroy(), KSPSetMonitor(), KSPLGTrueMonitorCreate()
 32: @*/
 33: int KSPLGMonitorCreate(char *host,char *label,int x,int y,int m,int n,PetscDrawLG *draw)
 34: {
 35:   PetscDraw win;
 36:   int       ierr;

 39:   PetscDrawCreate(PETSC_COMM_SELF,host,label,x,y,m,n,&win);
 40:   PetscDrawSetType(win,PETSC_DRAW_X);
 41:   PetscDrawLGCreate(win,1,draw);
 42:   PetscLogObjectParent(*draw,win);
 43:   return(0);
 44: }

 46: int KSPLGMonitor(KSP ksp,int n,PetscReal rnorm,void *monctx)
 47: {
 48:   PetscDrawLG lg = (PetscDrawLG) monctx;
 49:   int         ierr;
 50:   PetscReal   x,y;

 53:   if (!monctx) {
 54:     MPI_Comm comm;
 55:     PetscViewer viewer;

 57:     ierr   = PetscObjectGetComm((PetscObject)ksp,&comm);
 58:     viewer = PETSC_VIEWER_DRAW_(comm);
 59:     ierr   = PetscViewerDrawGetDrawLG(viewer,0,&lg);
 60:   }

 62:   if (!n) {PetscDrawLGReset(lg);}
 63:   x = (PetscReal) n;
 64:   if (rnorm > 0.0) y = log10(rnorm); else y = -15.0;
 65:   PetscDrawLGAddPoint(lg,&x,&y);
 66:   if (n < 20 || !(n % 5)) {
 67:     PetscDrawLGDraw(lg);
 68:   }
 69:   return(0);
 70: }
 71: 
 72: /*@C
 73:    KSPLGMonitorDestroy - Destroys a line graph context that was created 
 74:    with KSPLGMonitorCreate().

 76:    Collective on KSP

 78:    Input Parameter:
 79: .  draw - the drawing context

 81:    Level: intermediate

 83: .keywords: KSP, monitor, line graph, destroy

 85: .seealso: KSPLGMonitorCreate(), KSPLGTrueMonitorDestroy(), KSPSetMonitor()
 86: @*/
 87: int KSPLGMonitorDestroy(PetscDrawLG drawlg)
 88: {
 89:   PetscDraw draw;
 90:   int       ierr;

 93:   PetscDrawLGGetDraw(drawlg,&draw);
 94:   if (draw) { PetscDrawDestroy(draw);}
 95:   PetscDrawLGDestroy(drawlg);
 96:   return(0);
 97: }

 99: /*@C
100:    KSPLGTrueMonitorCreate - Creates a line graph context for use with 
101:    KSP to monitor convergence of true residual norms (as opposed to
102:    preconditioned residual norms).

104:    Collective on KSP

106:    Input Parameters:
107: +  host - the X display to open, or null for the local machine
108: .  label - the title to put in the title bar
109: .  x, y - the screen coordinates of the upper left coordinate of
110:           the window
111: -  m, n - the screen width and height in pixels

113:    Output Parameter:
114: .  draw - the drawing context

116:    Options Database Key:
117: .  -ksp_xtruemonitor - Sets true line graph monitor

119:    Notes: 
120:    Use KSPLGTrueMonitorDestroy() to destroy this line graph, not
121:    PetscDrawLGDestroy().

123:    Level: intermediate

125: .keywords: KSP, monitor, line graph, residual, create, true

127: .seealso: KSPLGMonitorDestroy(), KSPSetMonitor(), KSPDefaultMonitor()
128: @*/
129: int KSPLGTrueMonitorCreate(MPI_Comm comm,char *host,char *label,int x,int y,int m,int n,PetscDrawLG *draw)
130: {
131:   PetscDraw win;
132:   int       ierr,rank;

135:   MPI_Comm_rank(comm,&rank);
136:   if (rank) { *draw = 0; return(0);}

138:   PetscDrawCreate(PETSC_COMM_SELF,host,label,x,y,m,n,&win);
139:   PetscDrawSetType(win,PETSC_DRAW_X);
140:   PetscDrawLGCreate(win,2,draw);
141:   PetscLogObjectParent(*draw,win);
142:   return(0);
143: }

145: int KSPLGTrueMonitor(KSP ksp,int n,PetscReal rnorm,void *monctx)
146: {
147:   PetscDrawLG lg = (PetscDrawLG) monctx;
148:   PetscReal   x[2],y[2],scnorm;
149:   int         ierr,rank;
150:   Vec         resid,work;

153:   if (!monctx) {
154:     MPI_Comm    comm;
155:     PetscViewer viewer;

157:     ierr   = PetscObjectGetComm((PetscObject)ksp,&comm);
158:     viewer = PETSC_VIEWER_DRAW_(comm);
159:     ierr   = PetscViewerDrawGetDrawLG(viewer,0,&lg);
160:   }

162:   MPI_Comm_rank(ksp->comm,&rank);
163:   if (!rank) {
164:     if (!n) {PetscDrawLGReset(lg);}
165:     x[0] = x[1] = (PetscReal) n;
166:     if (rnorm > 0.0) y[0] = log10(rnorm); else y[0] = -15.0;
167:   }

169:   VecDuplicate(ksp->vec_rhs,&work);
170:   KSPBuildResidual(ksp,0,work,&resid);
171:   VecNorm(resid,NORM_2,&scnorm);
172:   VecDestroy(work);

174:   if (!rank) {
175:     if (scnorm > 0.0) y[1] = log10(scnorm); else y[1] = -15.0;
176:     PetscDrawLGAddPoint(lg,x,y);
177:     if (n <= 20 || (n % 3)) {
178:       PetscDrawLGDraw(lg);
179:     }
180:   }
181:   return(0);
182: }
183: 
184: /*@C
185:    KSPLGTrueMonitorDestroy - Destroys a line graph context that was created 
186:    with KSPLGTrueMonitorCreate().

188:    Collective on KSP

190:    Input Parameter:
191: .  draw - the drawing context

193:    Level: intermediate

195: .keywords: KSP, monitor, line graph, destroy, true

197: .seealso: KSPLGTrueMonitorCreate(), KSPSetMonitor()
198: @*/
199: int KSPLGTrueMonitorDestroy(PetscDrawLG drawlg)
200: {
201:   int       ierr;
202:   PetscDraw draw;

205:   PetscDrawLGGetDraw(drawlg,&draw);
206:   PetscDrawDestroy(draw);
207:   PetscDrawLGDestroy(drawlg);
208:   return(0);
209: }