LCOV - code coverage report
Current view: top level - svd/interface - svdmon.c (source / functions) Hit Total Coverage
Test: SLEPc Lines: 183 223 82.1 %
Date: 2021-08-02 00:32:28 Functions: 13 16 81.2 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       3             :    SLEPc - Scalable Library for Eigenvalue Problem Computations
       4             :    Copyright (c) 2002-2021, Universitat Politecnica de Valencia, Spain
       5             : 
       6             :    This file is part of SLEPc.
       7             :    SLEPc is distributed under a 2-clause BSD license (see LICENSE).
       8             :    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       9             : */
      10             : /*
      11             :    SVD routines related to monitors
      12             : */
      13             : 
      14             : #include <slepc/private/svdimpl.h>   /*I "slepcsvd.h" I*/
      15             : #include <petscdraw.h>
      16             : 
      17           3 : PetscErrorCode SVDMonitorLGCreate(MPI_Comm comm,const char host[],const char label[],const char metric[],PetscInt l,const char *names[],int x,int y,int m,int n,PetscDrawLG *lgctx)
      18             : {
      19           3 :   PetscDraw      draw;
      20           3 :   PetscDrawAxis  axis;
      21           3 :   PetscDrawLG    lg;
      22           3 :   PetscErrorCode ierr;
      23             : 
      24           3 :   PetscFunctionBegin;
      25           3 :   ierr = PetscDrawCreate(comm,host,label,x,y,m,n,&draw);CHKERRQ(ierr);
      26           3 :   ierr = PetscDrawSetFromOptions(draw);CHKERRQ(ierr);
      27           3 :   ierr = PetscDrawLGCreate(draw,l,&lg);CHKERRQ(ierr);
      28           3 :   if (names) { ierr = PetscDrawLGSetLegend(lg,names);CHKERRQ(ierr); }
      29           3 :   ierr = PetscDrawLGSetFromOptions(lg);CHKERRQ(ierr);
      30           3 :   ierr = PetscDrawLGGetAxis(lg,&axis);CHKERRQ(ierr);
      31           3 :   ierr = PetscDrawAxisSetLabels(axis,"Convergence","Iteration",metric);CHKERRQ(ierr);
      32           3 :   ierr = PetscDrawDestroy(&draw);CHKERRQ(ierr);
      33           3 :   *lgctx = lg;
      34           3 :   PetscFunctionReturn(0);
      35             : }
      36             : 
      37             : /*
      38             :    Runs the user provided monitor routines, if any.
      39             : */
      40        2591 : PetscErrorCode SVDMonitor(SVD svd,PetscInt it,PetscInt nconv,PetscReal *sigma,PetscReal *errest,PetscInt nest)
      41             : {
      42        2591 :   PetscErrorCode ierr;
      43        2591 :   PetscInt       i,n = svd->numbermonitors;
      44             : 
      45        2591 :   PetscFunctionBegin;
      46        2607 :   for (i=0;i<n;i++) {
      47          16 :     ierr = (*svd->monitor[i])(svd,it,nconv,sigma,errest,nest,svd->monitorcontext[i]);CHKERRQ(ierr);
      48             :   }
      49        2591 :   PetscFunctionReturn(0);
      50             : }
      51             : 
      52             : /*@C
      53             :    SVDMonitorSet - Sets an ADDITIONAL function to be called at every
      54             :    iteration to monitor the error estimates for each requested singular triplet.
      55             : 
      56             :    Logically Collective on svd
      57             : 
      58             :    Input Parameters:
      59             : +  svd     - singular value solver context obtained from SVDCreate()
      60             : .  monitor - pointer to function (if this is NULL, it turns off monitoring)
      61             : .  mctx    - [optional] context for private data for the
      62             :              monitor routine (use NULL if no context is desired)
      63             : -  monitordestroy - [optional] routine that frees monitor context (may be NULL)
      64             : 
      65             :    Calling Sequence of monitor:
      66             : $   monitor(SVD svd,PetscInt its,PetscInt nconv,PetscReal *sigma,PetscReal *errest,PetscInt nest,void *mctx)
      67             : 
      68             : +  svd    - singular value solver context obtained from SVDCreate()
      69             : .  its    - iteration number
      70             : .  nconv  - number of converged singular triplets
      71             : .  sigma  - singular values
      72             : .  errest - relative error estimates for each singular triplet
      73             : .  nest   - number of error estimates
      74             : -  mctx   - optional monitoring context, as set by SVDMonitorSet()
      75             : 
      76             :    Options Database Keys:
      77             : +    -svd_monitor        - print only the first error estimate
      78             : .    -svd_monitor_all    - print error estimates at each iteration
      79             : .    -svd_monitor_conv   - print the singular value approximations only when
      80             :       convergence has been reached
      81             : .    -svd_monitor draw::draw_lg - sets line graph monitor for the first unconverged
      82             :       approximate singular value
      83             : .    -svd_monitor_all draw::draw_lg - sets line graph monitor for all unconverged
      84             :       approximate singular values
      85             : .    -svd_monitor_conv draw::draw_lg - sets line graph monitor for convergence history
      86             : -    -svd_monitor_cancel - cancels all monitors that have been hardwired into
      87             :       a code by calls to SVDMonitorSet(), but does not cancel those set via
      88             :       the options database.
      89             : 
      90             :    Notes:
      91             :    Several different monitoring routines may be set by calling
      92             :    SVDMonitorSet() multiple times; all will be called in the
      93             :    order in which they were set.
      94             : 
      95             :    Level: intermediate
      96             : 
      97             : .seealso: SVDMonitorFirst(), SVDMonitorAll(), SVDMonitorCancel()
      98             : @*/
      99          20 : PetscErrorCode SVDMonitorSet(SVD svd,PetscErrorCode (*monitor)(SVD,PetscInt,PetscInt,PetscReal*,PetscReal*,PetscInt,void*),void *mctx,PetscErrorCode (*monitordestroy)(void**))
     100             : {
     101          20 :   PetscFunctionBegin;
     102          20 :   PetscValidHeaderSpecific(svd,SVD_CLASSID,1);
     103          20 :   if (svd->numbermonitors >= MAXSVDMONITORS) SETERRQ(PetscObjectComm((PetscObject)svd),PETSC_ERR_ARG_OUTOFRANGE,"Too many SVD monitors set");
     104          20 :   svd->monitor[svd->numbermonitors]           = monitor;
     105          20 :   svd->monitorcontext[svd->numbermonitors]    = (void*)mctx;
     106          20 :   svd->monitordestroy[svd->numbermonitors++]  = monitordestroy;
     107          20 :   PetscFunctionReturn(0);
     108             : }
     109             : 
     110             : /*@
     111             :    SVDMonitorCancel - Clears all monitors for an SVD object.
     112             : 
     113             :    Logically Collective on svd
     114             : 
     115             :    Input Parameters:
     116             : .  svd - singular value solver context obtained from SVDCreate()
     117             : 
     118             :    Options Database Key:
     119             : .    -svd_monitor_cancel - Cancels all monitors that have been hardwired
     120             :       into a code by calls to SVDMonitorSet(),
     121             :       but does not cancel those set via the options database.
     122             : 
     123             :    Level: intermediate
     124             : 
     125             : .seealso: SVDMonitorSet()
     126             : @*/
     127         155 : PetscErrorCode SVDMonitorCancel(SVD svd)
     128             : {
     129         155 :   PetscErrorCode ierr;
     130         155 :   PetscInt       i;
     131             : 
     132         155 :   PetscFunctionBegin;
     133         155 :   PetscValidHeaderSpecific(svd,SVD_CLASSID,1);
     134         175 :   for (i=0; i<svd->numbermonitors; i++) {
     135          20 :     if (svd->monitordestroy[i]) {
     136          20 :       ierr = (*svd->monitordestroy[i])(&svd->monitorcontext[i]);CHKERRQ(ierr);
     137             :     }
     138             :   }
     139         155 :   svd->numbermonitors = 0;
     140         155 :   PetscFunctionReturn(0);
     141             : }
     142             : 
     143             : /*@C
     144             :    SVDGetMonitorContext - Gets the monitor context, as set by
     145             :    SVDMonitorSet() for the FIRST monitor only.
     146             : 
     147             :    Not Collective
     148             : 
     149             :    Input Parameter:
     150             : .  svd - singular value solver context obtained from SVDCreate()
     151             : 
     152             :    Output Parameter:
     153             : .  ctx - monitor context
     154             : 
     155             :    Level: intermediate
     156             : 
     157             : .seealso: SVDMonitorSet()
     158             : @*/
     159           0 : PetscErrorCode SVDGetMonitorContext(SVD svd,void **ctx)
     160             : {
     161           0 :   PetscFunctionBegin;
     162           0 :   PetscValidHeaderSpecific(svd,SVD_CLASSID,1);
     163           0 :   *ctx = svd->monitorcontext[0];
     164           0 :   PetscFunctionReturn(0);
     165             : }
     166             : 
     167             : /*@C
     168             :    SVDMonitorFirst - Print the first unconverged approximate value and
     169             :    error estimate at each iteration of the singular value solver.
     170             : 
     171             :    Collective on svd
     172             : 
     173             :    Input Parameters:
     174             : +  svd    - singular value solver context
     175             : .  its    - iteration number
     176             : .  nconv  - number of converged singular triplets so far
     177             : .  sigma  - singular values
     178             : .  errest - error estimates
     179             : .  nest   - number of error estimates to display
     180             : -  vf     - viewer and format for monitoring
     181             : 
     182             :    Options Database Key:
     183             : .  -svd_monitor - activates SVDMonitorFirst()
     184             : 
     185             :    Level: intermediate
     186             : 
     187             : .seealso: SVDMonitorSet(), SVDMonitorAll(), SVDMonitorConverged()
     188             : @*/
     189           7 : PetscErrorCode SVDMonitorFirst(SVD svd,PetscInt its,PetscInt nconv,PetscReal *sigma,PetscReal *errest,PetscInt nest,PetscViewerAndFormat *vf)
     190             : {
     191           7 :   PetscErrorCode ierr;
     192           7 :   PetscViewer    viewer = vf->viewer;
     193             : 
     194           7 :   PetscFunctionBegin;
     195           7 :   PetscValidHeaderSpecific(svd,SVD_CLASSID,1);
     196           7 :   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,7);
     197           7 :   if (its==1 && ((PetscObject)svd)->prefix) {
     198           1 :     ierr = PetscViewerASCIIPrintf(viewer,"  Singular value approximations and residual norms for %s solve.\n",((PetscObject)svd)->prefix);CHKERRQ(ierr);
     199             :   }
     200           7 :   if (nconv<nest) {
     201           7 :     ierr = PetscViewerPushFormat(viewer,vf->format);CHKERRQ(ierr);
     202           7 :     ierr = PetscViewerASCIIAddTab(viewer,((PetscObject)svd)->tablevel);CHKERRQ(ierr);
     203           7 :     ierr = PetscViewerASCIIPrintf(viewer,"%3D SVD nconv=%D first unconverged value (error)",its,nconv);CHKERRQ(ierr);
     204           7 :     ierr = PetscViewerASCIIUseTabs(viewer,PETSC_FALSE);CHKERRQ(ierr);
     205           7 :     ierr = PetscViewerASCIIPrintf(viewer," %g (%10.8e)\n",(double)sigma[nconv],(double)errest[nconv]);CHKERRQ(ierr);
     206           7 :     ierr = PetscViewerASCIIUseTabs(viewer,PETSC_TRUE);CHKERRQ(ierr);
     207           7 :     ierr = PetscViewerASCIISubtractTab(viewer,((PetscObject)svd)->tablevel);CHKERRQ(ierr);
     208           7 :     ierr = PetscViewerPopFormat(viewer);CHKERRQ(ierr);
     209             :   }
     210           7 :   PetscFunctionReturn(0);
     211             : }
     212             : 
     213             : /*@C
     214             :    SVDMonitorAll - Print the current approximate values and
     215             :    error estimates at each iteration of the singular value solver.
     216             : 
     217             :    Collective on svd
     218             : 
     219             :    Input Parameters:
     220             : +  svd    - singular value solver context
     221             : .  its    - iteration number
     222             : .  nconv  - number of converged singular triplets so far
     223             : .  sigma  - singular values
     224             : .  errest - error estimates
     225             : .  nest   - number of error estimates to display
     226             : -  vf     - viewer and format for monitoring
     227             : 
     228             :    Options Database Key:
     229             : .  -svd_monitor_all - activates SVDMonitorAll()
     230             : 
     231             :    Level: intermediate
     232             : 
     233             : .seealso: SVDMonitorSet(), SVDMonitorFirst(), SVDMonitorConverged()
     234             : @*/
     235           2 : PetscErrorCode SVDMonitorAll(SVD svd,PetscInt its,PetscInt nconv,PetscReal *sigma,PetscReal *errest,PetscInt nest,PetscViewerAndFormat *vf)
     236             : {
     237           2 :   PetscErrorCode ierr;
     238           2 :   PetscInt       i;
     239           2 :   PetscViewer    viewer = vf->viewer;
     240             : 
     241           2 :   PetscFunctionBegin;
     242           2 :   PetscValidHeaderSpecific(svd,SVD_CLASSID,1);
     243           2 :   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,7);
     244           2 :   ierr = PetscViewerPushFormat(viewer,vf->format);CHKERRQ(ierr);
     245           2 :   ierr = PetscViewerASCIIAddTab(viewer,((PetscObject)svd)->tablevel);CHKERRQ(ierr);
     246           2 :   if (its==1 && ((PetscObject)svd)->prefix) {
     247           0 :     ierr = PetscViewerASCIIPrintf(viewer,"  Singular value approximations and residual norms for %s solve.\n",((PetscObject)svd)->prefix);CHKERRQ(ierr);
     248             :   }
     249           2 :   ierr = PetscViewerASCIIPrintf(viewer,"%3D SVD nconv=%D Values (Errors)",its,nconv);CHKERRQ(ierr);
     250           2 :   ierr = PetscViewerASCIIUseTabs(viewer,PETSC_FALSE);CHKERRQ(ierr);
     251          14 :   for (i=0;i<nest;i++) {
     252          12 :     ierr = PetscViewerASCIIPrintf(viewer," %g (%10.8e)",(double)sigma[i],(double)errest[i]);CHKERRQ(ierr);
     253             :   }
     254           2 :   ierr = PetscViewerASCIIPrintf(viewer,"\n");CHKERRQ(ierr);
     255           2 :   ierr = PetscViewerASCIIUseTabs(viewer,PETSC_TRUE);CHKERRQ(ierr);
     256           2 :   ierr = PetscViewerASCIISubtractTab(viewer,((PetscObject)svd)->tablevel);CHKERRQ(ierr);
     257           2 :   ierr = PetscViewerPopFormat(viewer);CHKERRQ(ierr);
     258           2 :   PetscFunctionReturn(0);
     259             : }
     260             : 
     261             : /*@C
     262             :    SVDMonitorConverged - Print the approximate values and
     263             :    error estimates as they converge.
     264             : 
     265             :    Collective on svd
     266             : 
     267             :    Input Parameters:
     268             : +  svd    - singular value solver context
     269             : .  its    - iteration number
     270             : .  nconv  - number of converged singular triplets so far
     271             : .  sigma  - singular values
     272             : .  errest - error estimates
     273             : .  nest   - number of error estimates to display
     274             : -  vf     - viewer and format for monitoring
     275             : 
     276             :    Options Database Key:
     277             : .  -svd_monitor_conv - activates SVDMonitorConverged()
     278             : 
     279             :    Level: intermediate
     280             : 
     281             : .seealso: SVDMonitorSet(), SVDMonitorFirst(), SVDMonitorAll()
     282             : @*/
     283           2 : PetscErrorCode SVDMonitorConverged(SVD svd,PetscInt its,PetscInt nconv,PetscReal *sigma,PetscReal *errest,PetscInt nest,PetscViewerAndFormat *vf)
     284             : {
     285           2 :   PetscErrorCode ierr;
     286           2 :   PetscInt       i;
     287           2 :   PetscViewer    viewer = vf->viewer;
     288           2 :   SlepcConvMon   ctx;
     289             : 
     290           2 :   PetscFunctionBegin;
     291           2 :   PetscValidHeaderSpecific(svd,SVD_CLASSID,1);
     292           2 :   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,7);
     293           2 :   ctx = (SlepcConvMon)vf->data;
     294           2 :   if (its==1 && ((PetscObject)svd)->prefix) {
     295           0 :     ierr = PetscViewerASCIIPrintf(viewer,"  Convergence history for %s solve.\n",((PetscObject)svd)->prefix);CHKERRQ(ierr);
     296             :   }
     297           2 :   if (its==1) ctx->oldnconv = 0;
     298           2 :   if (ctx->oldnconv!=nconv) {
     299           2 :     ierr = PetscViewerPushFormat(viewer,vf->format);CHKERRQ(ierr);
     300           2 :     ierr = PetscViewerASCIIAddTab(viewer,((PetscObject)svd)->tablevel);CHKERRQ(ierr);
     301          14 :     for (i=ctx->oldnconv;i<nconv;i++) {
     302          12 :       ierr = PetscViewerASCIIPrintf(viewer,"%3D SVD converged value (error) #%D",its,i);CHKERRQ(ierr);
     303          12 :       ierr = PetscViewerASCIIUseTabs(viewer,PETSC_FALSE);CHKERRQ(ierr);
     304          12 :       ierr = PetscViewerASCIIPrintf(viewer," %g (%10.8e)\n",(double)sigma[i],(double)errest[i]);CHKERRQ(ierr);
     305          12 :       ierr = PetscViewerASCIIUseTabs(viewer,PETSC_TRUE);CHKERRQ(ierr);
     306             :     }
     307           2 :     ierr = PetscViewerASCIISubtractTab(viewer,((PetscObject)svd)->tablevel);CHKERRQ(ierr);
     308           2 :     ierr = PetscViewerPopFormat(viewer);CHKERRQ(ierr);
     309           2 :     ctx->oldnconv = nconv;
     310             :   }
     311           2 :   PetscFunctionReturn(0);
     312             : }
     313             : 
     314           2 : PetscErrorCode SVDMonitorConvergedCreate(PetscViewer viewer,PetscViewerFormat format,void *ctx,PetscViewerAndFormat **vf)
     315             : {
     316           2 :   PetscErrorCode ierr;
     317           2 :   SlepcConvMon   mctx;
     318             : 
     319           2 :   PetscFunctionBegin;
     320           2 :   ierr = PetscViewerAndFormatCreate(viewer,format,vf);CHKERRQ(ierr);
     321           2 :   ierr = PetscNew(&mctx);CHKERRQ(ierr);
     322           2 :   mctx->ctx = ctx;
     323           2 :   (*vf)->data = (void*)mctx;
     324           2 :   PetscFunctionReturn(0);
     325             : }
     326             : 
     327           2 : PetscErrorCode SVDMonitorConvergedDestroy(PetscViewerAndFormat **vf)
     328             : {
     329           2 :   PetscErrorCode ierr;
     330             : 
     331           2 :   PetscFunctionBegin;
     332           2 :   if (!*vf) PetscFunctionReturn(0);
     333           2 :   ierr = PetscFree((*vf)->data);CHKERRQ(ierr);
     334           2 :   ierr = PetscViewerDestroy(&(*vf)->viewer);CHKERRQ(ierr);
     335           2 :   ierr = PetscDrawLGDestroy(&(*vf)->lg);CHKERRQ(ierr);
     336           2 :   ierr = PetscFree(*vf);CHKERRQ(ierr);
     337           2 :   PetscFunctionReturn(0);
     338             : }
     339             : 
     340             : /*@C
     341             :    SVDMonitorFirstDrawLG - Plots the error estimate of the first unconverged
     342             :    approximation at each iteration of the singular value solver.
     343             : 
     344             :    Collective on svd
     345             : 
     346             :    Input Parameters:
     347             : +  svd    - singular value solver context
     348             : .  its    - iteration number
     349             : .  its    - iteration number
     350             : .  nconv  - number of converged singular triplets so far
     351             : .  sigma  - singular values
     352             : .  errest - error estimates
     353             : .  nest   - number of error estimates to display
     354             : -  vf     - viewer and format for monitoring
     355             : 
     356             :    Options Database Key:
     357             : .  -svd_monitor draw::draw_lg - activates SVDMonitorFirstDrawLG()
     358             : 
     359             :    Level: intermediate
     360             : 
     361             : .seealso: SVDMonitorSet()
     362             : @*/
     363           4 : PetscErrorCode SVDMonitorFirstDrawLG(SVD svd,PetscInt its,PetscInt nconv,PetscReal *sigma,PetscReal *errest,PetscInt nest,PetscViewerAndFormat *vf)
     364             : {
     365           4 :   PetscErrorCode ierr;
     366           4 :   PetscViewer    viewer = vf->viewer;
     367           4 :   PetscDrawLG    lg = vf->lg;
     368           4 :   PetscReal      x,y;
     369             : 
     370           4 :   PetscFunctionBegin;
     371           4 :   PetscValidHeaderSpecific(svd,SVD_CLASSID,1);
     372           4 :   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,7);
     373           4 :   PetscValidHeaderSpecific(lg,PETSC_DRAWLG_CLASSID,7);
     374           4 :   ierr = PetscViewerPushFormat(viewer,vf->format);CHKERRQ(ierr);
     375           4 :   if (its==1) {
     376           2 :     ierr = PetscDrawLGReset(lg);CHKERRQ(ierr);
     377           2 :     ierr = PetscDrawLGSetDimension(lg,1);CHKERRQ(ierr);
     378           2 :     ierr = PetscDrawLGSetLimits(lg,1,1,PetscLog10Real(svd->tol)-2,0.0);CHKERRQ(ierr);
     379             :   }
     380           4 :   if (nconv<nest) {
     381           3 :     x = (PetscReal)its;
     382           3 :     if (errest[nconv] > 0.0) y = PetscLog10Real(errest[nconv]);
     383           0 :     else y = 0.0;
     384           3 :     ierr = PetscDrawLGAddPoint(lg,&x,&y);CHKERRQ(ierr);
     385           3 :     if (its <= 20 || !(its % 5) || svd->reason) {
     386           3 :       ierr = PetscDrawLGDraw(lg);CHKERRQ(ierr);
     387           3 :       ierr = PetscDrawLGSave(lg);CHKERRQ(ierr);
     388             :     }
     389             :   }
     390           4 :   ierr = PetscViewerPopFormat(viewer);CHKERRQ(ierr);
     391           4 :   PetscFunctionReturn(0);
     392             : }
     393             : 
     394             : /*@C
     395             :    SVDMonitorFirstDrawLGCreate - Creates the plotter for the first error estimate.
     396             : 
     397             :    Collective on viewer
     398             : 
     399             :    Input Parameters:
     400             : +  viewer - the viewer
     401             : .  format - the viewer format
     402             : -  ctx    - an optional user context
     403             : 
     404             :    Output Parameter:
     405             : .  vf     - the viewer and format context
     406             : 
     407             :    Level: intermediate
     408             : 
     409             : .seealso: SVDMonitorSet()
     410             : @*/
     411           2 : PetscErrorCode SVDMonitorFirstDrawLGCreate(PetscViewer viewer,PetscViewerFormat format,void *ctx,PetscViewerAndFormat **vf)
     412             : {
     413           2 :   PetscErrorCode ierr;
     414             : 
     415           2 :   PetscFunctionBegin;
     416           2 :   ierr = PetscViewerAndFormatCreate(viewer,format,vf);CHKERRQ(ierr);
     417           2 :   (*vf)->data = ctx;
     418           2 :   ierr = SVDMonitorLGCreate(PetscObjectComm((PetscObject)viewer),NULL,"First Error Estimate","Log Error Estimate",1,NULL,PETSC_DECIDE,PETSC_DECIDE,400,300,&(*vf)->lg);CHKERRQ(ierr);
     419           2 :   PetscFunctionReturn(0);
     420             : }
     421             : 
     422             : /*@C
     423             :    SVDMonitorAllDrawLG - Plots the error estimate of all unconverged
     424             :    approximations at each iteration of the singular value solver.
     425             : 
     426             :    Collective on svd
     427             : 
     428             :    Input Parameters:
     429             : +  svd    - singular value solver context
     430             : .  its    - iteration number
     431             : .  its    - iteration number
     432             : .  nconv  - number of converged singular triplets so far
     433             : .  sigma  - singular values
     434             : .  errest - error estimates
     435             : .  nest   - number of error estimates to display
     436             : -  vf     - viewer and format for monitoring
     437             : 
     438             :    Options Database Key:
     439             : .  -svd_monitor_all draw::draw_lg - activates SVDMonitorAllDrawLG()
     440             : 
     441             :    Level: intermediate
     442             : 
     443             : .seealso: SVDMonitorSet()
     444             : @*/
     445           1 : PetscErrorCode SVDMonitorAllDrawLG(SVD svd,PetscInt its,PetscInt nconv,PetscReal *sigma,PetscReal *errest,PetscInt nest,PetscViewerAndFormat *vf)
     446             : {
     447           1 :   PetscErrorCode ierr;
     448           1 :   PetscViewer    viewer = vf->viewer;
     449           1 :   PetscDrawLG    lg = vf->lg;
     450           1 :   PetscInt       i,n = PetscMin(svd->nsv,255);
     451           1 :   PetscReal      *x,*y;
     452             : 
     453           1 :   PetscFunctionBegin;
     454           1 :   PetscValidHeaderSpecific(svd,SVD_CLASSID,1);
     455           1 :   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,7);
     456           1 :   PetscValidHeaderSpecific(lg,PETSC_DRAWLG_CLASSID,7);
     457           1 :   ierr = PetscViewerPushFormat(viewer,vf->format);CHKERRQ(ierr);
     458           1 :   if (its==1) {
     459           1 :     ierr = PetscDrawLGReset(lg);CHKERRQ(ierr);
     460           1 :     ierr = PetscDrawLGSetDimension(lg,n);CHKERRQ(ierr);
     461           1 :     ierr = PetscDrawLGSetLimits(lg,1,1,PetscLog10Real(svd->tol)-2,0.0);CHKERRQ(ierr);
     462             :   }
     463           1 :   ierr = PetscMalloc2(n,&x,n,&y);CHKERRQ(ierr);
     464           2 :   for (i=0;i<n;i++) {
     465           1 :     x[i] = (PetscReal)its;
     466           1 :     if (i < nest && errest[i] > 0.0) y[i] = PetscLog10Real(errest[i]);
     467           1 :     else y[i] = 0.0;
     468             :   }
     469           1 :   ierr = PetscDrawLGAddPoint(lg,x,y);CHKERRQ(ierr);
     470           1 :   if (its <= 20 || !(its % 5) || svd->reason) {
     471           1 :     ierr = PetscDrawLGDraw(lg);CHKERRQ(ierr);
     472           1 :     ierr = PetscDrawLGSave(lg);CHKERRQ(ierr);
     473             :   }
     474           1 :   ierr = PetscFree2(x,y);CHKERRQ(ierr);
     475           1 :   ierr = PetscViewerPopFormat(viewer);CHKERRQ(ierr);
     476           1 :   PetscFunctionReturn(0);
     477             : }
     478             : 
     479             : /*@C
     480             :    SVDMonitorAllDrawLGCreate - Creates the plotter for all the error estimates.
     481             : 
     482             :    Collective on viewer
     483             : 
     484             :    Input Parameters:
     485             : +  viewer - the viewer
     486             : .  format - the viewer format
     487             : -  ctx    - an optional user context
     488             : 
     489             :    Output Parameter:
     490             : .  vf     - the viewer and format context
     491             : 
     492             :    Level: intermediate
     493             : 
     494             : .seealso: SVDMonitorSet()
     495             : @*/
     496           1 : PetscErrorCode SVDMonitorAllDrawLGCreate(PetscViewer viewer,PetscViewerFormat format,void *ctx,PetscViewerAndFormat **vf)
     497             : {
     498           1 :   PetscErrorCode ierr;
     499             : 
     500           1 :   PetscFunctionBegin;
     501           1 :   ierr = PetscViewerAndFormatCreate(viewer,format,vf);CHKERRQ(ierr);
     502           1 :   (*vf)->data = ctx;
     503           1 :   ierr = SVDMonitorLGCreate(PetscObjectComm((PetscObject)viewer),NULL,"All Error Estimates","Log Error Estimate",1,NULL,PETSC_DECIDE,PETSC_DECIDE,400,300,&(*vf)->lg);CHKERRQ(ierr);
     504           1 :   PetscFunctionReturn(0);
     505             : }
     506             : 
     507             : /*@C
     508             :    SVDMonitorConvergedDrawLG - Plots the number of converged eigenvalues
     509             :    at each iteration of the singular value solver.
     510             : 
     511             :    Collective on svd
     512             : 
     513             :    Input Parameters:
     514             : +  svd    - singular value solver context
     515             : .  its    - iteration number
     516             : .  its    - iteration number
     517             : .  nconv  - number of converged singular triplets so far
     518             : .  sigma  - singular values
     519             : .  errest - error estimates
     520             : .  nest   - number of error estimates to display
     521             : -  vf     - viewer and format for monitoring
     522             : 
     523             :    Options Database Key:
     524             : .  -svd_monitor_conv draw::draw_lg - activates SVDMonitorConvergedDrawLG()
     525             : 
     526             :    Level: intermediate
     527             : 
     528             : .seealso: SVDMonitorSet()
     529             : @*/
     530           0 : PetscErrorCode SVDMonitorConvergedDrawLG(SVD svd,PetscInt its,PetscInt nconv,PetscReal *sigma,PetscReal *errest,PetscInt nest,PetscViewerAndFormat *vf)
     531             : {
     532           0 :   PetscErrorCode   ierr;
     533           0 :   PetscViewer      viewer = vf->viewer;
     534           0 :   PetscDrawLG      lg = vf->lg;
     535           0 :   PetscReal        x,y;
     536             : 
     537           0 :   PetscFunctionBegin;
     538           0 :   PetscValidHeaderSpecific(svd,SVD_CLASSID,1);
     539           0 :   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,7);
     540           0 :   PetscValidHeaderSpecific(lg,PETSC_DRAWLG_CLASSID,7);
     541           0 :   ierr = PetscViewerPushFormat(viewer,vf->format);CHKERRQ(ierr);
     542           0 :   if (its==1) {
     543           0 :     ierr = PetscDrawLGReset(lg);CHKERRQ(ierr);
     544           0 :     ierr = PetscDrawLGSetDimension(lg,1);CHKERRQ(ierr);
     545           0 :     ierr = PetscDrawLGSetLimits(lg,1,1,0,svd->nsv);CHKERRQ(ierr);
     546             :   }
     547           0 :   x = (PetscReal)its;
     548           0 :   y = (PetscReal)svd->nconv;
     549           0 :   ierr = PetscDrawLGAddPoint(lg,&x,&y);CHKERRQ(ierr);
     550           0 :   if (its <= 20 || !(its % 5) || svd->reason) {
     551           0 :     ierr = PetscDrawLGDraw(lg);CHKERRQ(ierr);
     552           0 :     ierr = PetscDrawLGSave(lg);CHKERRQ(ierr);
     553             :   }
     554           0 :   ierr = PetscViewerPopFormat(viewer);CHKERRQ(ierr);
     555           0 :   PetscFunctionReturn(0);
     556             : }
     557             : 
     558             : /*@C
     559             :    SVDMonitorConvergedDrawLGCreate - Creates the plotter for the convergence history.
     560             : 
     561             :    Collective on viewer
     562             : 
     563             :    Input Parameters:
     564             : +  viewer - the viewer
     565             : .  format - the viewer format
     566             : -  ctx    - an optional user context
     567             : 
     568             :    Output Parameter:
     569             : .  vf     - the viewer and format context
     570             : 
     571             :    Level: intermediate
     572             : 
     573             : .seealso: SVDMonitorSet()
     574             : @*/
     575           0 : PetscErrorCode SVDMonitorConvergedDrawLGCreate(PetscViewer viewer,PetscViewerFormat format,void *ctx,PetscViewerAndFormat **vf)
     576             : {
     577           0 :   PetscErrorCode ierr;
     578           0 :   SlepcConvMon   mctx;
     579             : 
     580           0 :   PetscFunctionBegin;
     581           0 :   ierr = PetscViewerAndFormatCreate(viewer,format,vf);CHKERRQ(ierr);
     582           0 :   ierr = PetscNew(&mctx);CHKERRQ(ierr);
     583           0 :   mctx->ctx = ctx;
     584           0 :   (*vf)->data = (void*)mctx;
     585           0 :   ierr = SVDMonitorLGCreate(PetscObjectComm((PetscObject)viewer),NULL,"Convergence History","Number Converged",1,NULL,PETSC_DECIDE,PETSC_DECIDE,400,300,&(*vf)->lg);CHKERRQ(ierr);
     586           0 :   PetscFunctionReturn(0);
     587             : }
     588             : 

Generated by: LCOV version 1.14