LCOV - code coverage report
Current view: top level - nep/interface - nepmon.c (source / functions) Hit Total Coverage
Test: SLEPc Lines: 186 226 82.3 %
Date: 2021-08-02 00:35:43 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             :    NEP routines related to monitors
      12             : */
      13             : 
      14             : #include <slepc/private/nepimpl.h>      /*I "slepcnep.h" I*/
      15             : #include <petscdraw.h>
      16             : 
      17           3 : PetscErrorCode NEPMonitorLGCreate(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        1035 : PetscErrorCode NEPMonitor(NEP nep,PetscInt it,PetscInt nconv,PetscScalar *eigr,PetscScalar *eigi,PetscReal *errest,PetscInt nest)
      41             : {
      42        1035 :   PetscErrorCode ierr;
      43        1035 :   PetscInt       i,n = nep->numbermonitors;
      44             : 
      45        1035 :   PetscFunctionBegin;
      46        1080 :   for (i=0;i<n;i++) {
      47          45 :     ierr = (*nep->monitor[i])(nep,it,nconv,eigr,eigi,errest,nest,nep->monitorcontext[i]);CHKERRQ(ierr);
      48             :   }
      49        1035 :   PetscFunctionReturn(0);
      50             : }
      51             : 
      52             : /*@C
      53             :    NEPMonitorSet - Sets an ADDITIONAL function to be called at every
      54             :    iteration to monitor the error estimates for each requested eigenpair.
      55             : 
      56             :    Logically Collective on nep
      57             : 
      58             :    Input Parameters:
      59             : +  nep     - eigensolver context obtained from NEPCreate()
      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(NEP nep,int its,int nconv,PetscScalar *eigr,PetscScalar *eigi,PetscReal* errest,int nest,void *mctx)
      67             : 
      68             : +  nep    - nonlinear eigensolver context obtained from NEPCreate()
      69             : .  its    - iteration number
      70             : .  nconv  - number of converged eigenpairs
      71             : .  eigr   - real part of the eigenvalues
      72             : .  eigi   - imaginary part of the eigenvalues
      73             : .  errest - error estimates for each eigenpair
      74             : .  nest   - number of error estimates
      75             : -  mctx   - optional monitoring context, as set by NEPMonitorSet()
      76             : 
      77             :    Options Database Keys:
      78             : +    -nep_monitor        - print only the first error estimate
      79             : .    -nep_monitor_all    - print error estimates at each iteration
      80             : .    -nep_monitor_conv   - print the eigenvalue approximations only when
      81             :       convergence has been reached
      82             : .    -nep_monitor draw::draw_lg - sets line graph monitor for the first unconverged
      83             :       approximate eigenvalue
      84             : .    -nep_monitor_all draw::draw_lg - sets line graph monitor for all unconverged
      85             :       approximate eigenvalues
      86             : .    -nep_monitor_conv draw::draw_lg - sets line graph monitor for convergence history
      87             : -    -nep_monitor_cancel - cancels all monitors that have been hardwired into
      88             :       a code by calls to NEPMonitorSet(), but does not cancel those set via
      89             :       the options database.
      90             : 
      91             :    Notes:
      92             :    Several different monitoring routines may be set by calling
      93             :    NEPMonitorSet() multiple times; all will be called in the
      94             :    order in which they were set.
      95             : 
      96             :    Level: intermediate
      97             : 
      98             : .seealso: NEPMonitorFirst(), NEPMonitorAll(), NEPMonitorCancel()
      99             : @*/
     100           7 : PetscErrorCode NEPMonitorSet(NEP nep,PetscErrorCode (*monitor)(NEP,PetscInt,PetscInt,PetscScalar*,PetscScalar*,PetscReal*,PetscInt,void*),void *mctx,PetscErrorCode (*monitordestroy)(void**))
     101             : {
     102           7 :   PetscFunctionBegin;
     103           7 :   PetscValidHeaderSpecific(nep,NEP_CLASSID,1);
     104           7 :   if (nep->numbermonitors >= MAXNEPMONITORS) SETERRQ(PetscObjectComm((PetscObject)nep),PETSC_ERR_ARG_OUTOFRANGE,"Too many NEP monitors set");
     105           7 :   nep->monitor[nep->numbermonitors]           = monitor;
     106           7 :   nep->monitorcontext[nep->numbermonitors]    = (void*)mctx;
     107           7 :   nep->monitordestroy[nep->numbermonitors++]  = monitordestroy;
     108           7 :   PetscFunctionReturn(0);
     109             : }
     110             : 
     111             : /*@
     112             :    NEPMonitorCancel - Clears all monitors for a NEP object.
     113             : 
     114             :    Logically Collective on nep
     115             : 
     116             :    Input Parameters:
     117             : .  nep - eigensolver context obtained from NEPCreate()
     118             : 
     119             :    Options Database Key:
     120             : .    -nep_monitor_cancel - Cancels all monitors that have been hardwired
     121             :       into a code by calls to NEPMonitorSet(),
     122             :       but does not cancel those set via the options database.
     123             : 
     124             :    Level: intermediate
     125             : 
     126             : .seealso: NEPMonitorSet()
     127             : @*/
     128         111 : PetscErrorCode NEPMonitorCancel(NEP nep)
     129             : {
     130         111 :   PetscErrorCode ierr;
     131         111 :   PetscInt       i;
     132             : 
     133         111 :   PetscFunctionBegin;
     134         111 :   PetscValidHeaderSpecific(nep,NEP_CLASSID,1);
     135         118 :   for (i=0; i<nep->numbermonitors; i++) {
     136           7 :     if (nep->monitordestroy[i]) {
     137           7 :       ierr = (*nep->monitordestroy[i])(&nep->monitorcontext[i]);CHKERRQ(ierr);
     138             :     }
     139             :   }
     140         111 :   nep->numbermonitors = 0;
     141         111 :   PetscFunctionReturn(0);
     142             : }
     143             : 
     144             : /*@C
     145             :    NEPGetMonitorContext - Gets the monitor context, as set by
     146             :    NEPMonitorSet() for the FIRST monitor only.
     147             : 
     148             :    Not Collective
     149             : 
     150             :    Input Parameter:
     151             : .  nep - eigensolver context obtained from NEPCreate()
     152             : 
     153             :    Output Parameter:
     154             : .  ctx - monitor context
     155             : 
     156             :    Level: intermediate
     157             : 
     158             : .seealso: NEPMonitorSet(), NEPDefaultMonitor()
     159             : @*/
     160           0 : PetscErrorCode NEPGetMonitorContext(NEP nep,void **ctx)
     161             : {
     162           0 :   PetscFunctionBegin;
     163           0 :   PetscValidHeaderSpecific(nep,NEP_CLASSID,1);
     164           0 :   *ctx = nep->monitorcontext[0];
     165           0 :   PetscFunctionReturn(0);
     166             : }
     167             : 
     168             : /*@C
     169             :    NEPMonitorFirst - Print the first unconverged approximate value and
     170             :    error estimate at each iteration of the nonlinear eigensolver.
     171             : 
     172             :    Collective on nep
     173             : 
     174             :    Input Parameters:
     175             : +  nep    - nonlinear eigensolver context
     176             : .  its    - iteration number
     177             : .  nconv  - number of converged eigenpairs so far
     178             : .  eigr   - real part of the eigenvalues
     179             : .  eigi   - imaginary part of the eigenvalues
     180             : .  errest - error estimates
     181             : .  nest   - number of error estimates to display
     182             : -  vf     - viewer and format for monitoring
     183             : 
     184             :    Options Database Key:
     185             : .  -nep_monitor - activates NEPMonitorFirst()
     186             : 
     187             :    Level: intermediate
     188             : 
     189             : .seealso: NEPMonitorSet(), NEPMonitorAll(), NEPMonitorConverged()
     190             : @*/
     191           9 : PetscErrorCode NEPMonitorFirst(NEP nep,PetscInt its,PetscInt nconv,PetscScalar *eigr,PetscScalar *eigi,PetscReal *errest,PetscInt nest,PetscViewerAndFormat *vf)
     192             : {
     193           9 :   PetscErrorCode ierr;
     194           9 :   PetscViewer    viewer = vf->viewer;
     195             : 
     196           9 :   PetscFunctionBegin;
     197           9 :   PetscValidHeaderSpecific(nep,NEP_CLASSID,1);
     198           9 :   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,8);
     199           9 :   if (its==1 && ((PetscObject)nep)->prefix) {
     200           0 :     ierr = PetscViewerASCIIPrintf(viewer,"  Eigenvalue approximations and residual norms for %s solve.\n",((PetscObject)nep)->prefix);CHKERRQ(ierr);
     201             :   }
     202           9 :   if (nconv<nest) {
     203           8 :     ierr = PetscViewerPushFormat(viewer,vf->format);CHKERRQ(ierr);
     204           8 :     ierr = PetscViewerASCIIAddTab(viewer,((PetscObject)nep)->tablevel);CHKERRQ(ierr);
     205           8 :     ierr = PetscViewerASCIIPrintf(viewer,"%3D NEP nconv=%D first unconverged value (error)",its,nconv);CHKERRQ(ierr);
     206           8 :     ierr = PetscViewerASCIIUseTabs(viewer,PETSC_FALSE);CHKERRQ(ierr);
     207             : #if defined(PETSC_USE_COMPLEX)
     208           8 :     ierr = PetscViewerASCIIPrintf(viewer," %g%+gi",(double)PetscRealPart(eigr[nconv]),(double)PetscImaginaryPart(eigr[nconv]));CHKERRQ(ierr);
     209             : #else
     210             :     ierr = PetscViewerASCIIPrintf(viewer," %g",(double)eigr[nconv]);CHKERRQ(ierr);
     211             :     if (eigi[nconv]!=0.0) { ierr = PetscViewerASCIIPrintf(viewer,"%+gi",(double)eigi[nconv]);CHKERRQ(ierr); }
     212             : #endif
     213           8 :     ierr = PetscViewerASCIIPrintf(viewer," (%10.8e)\n",(double)errest[nconv]);CHKERRQ(ierr);
     214           8 :     ierr = PetscViewerASCIIUseTabs(viewer,PETSC_TRUE);CHKERRQ(ierr);
     215           8 :     ierr = PetscViewerASCIISubtractTab(viewer,((PetscObject)nep)->tablevel);CHKERRQ(ierr);
     216           8 :     ierr = PetscViewerPopFormat(viewer);CHKERRQ(ierr);
     217             :   }
     218           9 :   PetscFunctionReturn(0);
     219             : }
     220             : 
     221             : /*@C
     222             :    NEPMonitorAll - Print the current approximate values and
     223             :    error estimates at each iteration of the nonlinear eigensolver.
     224             : 
     225             :    Collective on nep
     226             : 
     227             :    Input Parameters:
     228             : +  nep    - nonlinear eigensolver context
     229             : .  its    - iteration number
     230             : .  nconv  - number of converged eigenpairs so far
     231             : .  eigr   - real part of the eigenvalues
     232             : .  eigi   - imaginary part of the eigenvalues
     233             : .  errest - error estimates
     234             : .  nest   - number of error estimates to display
     235             : -  vf     - viewer and format for monitoring
     236             : 
     237             :    Options Database Key:
     238             : .  -nep_monitor_all - activates NEPMonitorAll()
     239             : 
     240             :    Level: intermediate
     241             : 
     242             : .seealso: NEPMonitorSet(), NEPMonitorFirst(), NEPMonitorConverged()
     243             : @*/
     244           5 : PetscErrorCode NEPMonitorAll(NEP nep,PetscInt its,PetscInt nconv,PetscScalar *eigr,PetscScalar *eigi,PetscReal *errest,PetscInt nest,PetscViewerAndFormat *vf)
     245             : {
     246           5 :   PetscErrorCode ierr;
     247           5 :   PetscInt       i;
     248           5 :   PetscViewer    viewer = vf->viewer;
     249             : 
     250           5 :   PetscFunctionBegin;
     251           5 :   PetscValidHeaderSpecific(nep,NEP_CLASSID,1);
     252           5 :   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,8);
     253           5 :   ierr = PetscViewerPushFormat(viewer,vf->format);CHKERRQ(ierr);
     254           5 :   ierr = PetscViewerASCIIAddTab(viewer,((PetscObject)nep)->tablevel);CHKERRQ(ierr);
     255           5 :   if (its==1 && ((PetscObject)nep)->prefix) {
     256           0 :     ierr = PetscViewerASCIIPrintf(viewer,"  Eigenvalue approximations and residual norms for %s solve.\n",((PetscObject)nep)->prefix);CHKERRQ(ierr);
     257             :   }
     258           5 :   ierr = PetscViewerASCIIPrintf(viewer,"%3D NEP nconv=%D Values (Errors)",its,nconv);CHKERRQ(ierr);
     259           5 :   ierr = PetscViewerASCIIUseTabs(viewer,PETSC_FALSE);CHKERRQ(ierr);
     260          10 :   for (i=0;i<nest;i++) {
     261             : #if defined(PETSC_USE_COMPLEX)
     262           5 :     ierr = PetscViewerASCIIPrintf(viewer," %g%+gi",(double)PetscRealPart(eigr[i]),(double)PetscImaginaryPart(eigr[i]));CHKERRQ(ierr);
     263             : #else
     264             :     ierr = PetscViewerASCIIPrintf(viewer," %g",(double)eigr[i]);CHKERRQ(ierr);
     265             :     if (eigi[i]!=0.0) { ierr = PetscViewerASCIIPrintf(viewer,"%+gi",(double)eigi[i]);CHKERRQ(ierr); }
     266             : #endif
     267           5 :     ierr = PetscViewerASCIIPrintf(viewer," (%10.8e)",(double)errest[i]);CHKERRQ(ierr);
     268             :   }
     269           5 :   ierr = PetscViewerASCIIPrintf(viewer,"\n");CHKERRQ(ierr);
     270           5 :   ierr = PetscViewerASCIIUseTabs(viewer,PETSC_TRUE);CHKERRQ(ierr);
     271           5 :   ierr = PetscViewerASCIISubtractTab(viewer,((PetscObject)nep)->tablevel);CHKERRQ(ierr);
     272           5 :   ierr = PetscViewerPopFormat(viewer);CHKERRQ(ierr);
     273           5 :   PetscFunctionReturn(0);
     274             : }
     275             : 
     276             : /*@C
     277             :    NEPMonitorConverged - Print the approximate values and
     278             :    error estimates as they converge.
     279             : 
     280             :    Collective on nep
     281             : 
     282             :    Input Parameters:
     283             : +  nep    - nonlinear eigensolver context
     284             : .  its    - iteration number
     285             : .  nconv  - number of converged eigenpairs so far
     286             : .  eigr   - real part of the eigenvalues
     287             : .  eigi   - imaginary part of the eigenvalues
     288             : .  errest - error estimates
     289             : .  nest   - number of error estimates to display
     290             : -  vf     - viewer and format for monitoring
     291             : 
     292             :    Options Database Key:
     293             : .  -nep_monitor_conv - activates NEPMonitorConverged()
     294             : 
     295             :    Level: intermediate
     296             : 
     297             : .seealso: NEPMonitorSet(), NEPMonitorFirst(), NEPMonitorAll()
     298             : @*/
     299           6 : PetscErrorCode NEPMonitorConverged(NEP nep,PetscInt its,PetscInt nconv,PetscScalar *eigr,PetscScalar *eigi,PetscReal *errest,PetscInt nest,PetscViewerAndFormat *vf)
     300             : {
     301           6 :   PetscErrorCode ierr;
     302           6 :   PetscInt       i;
     303           6 :   PetscViewer    viewer = vf->viewer;
     304           6 :   SlepcConvMon   ctx;
     305             : 
     306           6 :   PetscFunctionBegin;
     307           6 :   PetscValidHeaderSpecific(nep,NEP_CLASSID,1);
     308           6 :   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,8);
     309           6 :   ctx = (SlepcConvMon)vf->data;
     310           6 :   if (its==1 && ((PetscObject)nep)->prefix) {
     311           1 :     ierr = PetscViewerASCIIPrintf(viewer,"  Convergence history for %s solve.\n",((PetscObject)nep)->prefix);CHKERRQ(ierr);
     312             :   }
     313           6 :   if (its==1) ctx->oldnconv = 0;
     314           6 :   if (ctx->oldnconv!=nconv) {
     315           1 :     ierr = PetscViewerPushFormat(viewer,vf->format);CHKERRQ(ierr);
     316           1 :     ierr = PetscViewerASCIIAddTab(viewer,((PetscObject)nep)->tablevel);CHKERRQ(ierr);
     317           2 :     for (i=ctx->oldnconv;i<nconv;i++) {
     318           1 :       ierr = PetscViewerASCIIPrintf(viewer,"%3D NEP converged value (error) #%D",its,i);CHKERRQ(ierr);
     319           1 :       ierr = PetscViewerASCIIUseTabs(viewer,PETSC_FALSE);CHKERRQ(ierr);
     320             : #if defined(PETSC_USE_COMPLEX)
     321           1 :       ierr = PetscViewerASCIIPrintf(viewer," %g%+gi",(double)PetscRealPart(eigr[i]),(double)PetscImaginaryPart(eigr[i]));CHKERRQ(ierr);
     322             : #else
     323             :       ierr = PetscViewerASCIIPrintf(viewer," %g",(double)eigr[i]);CHKERRQ(ierr);
     324             :       if (eigi[i]!=0.0) { ierr = PetscViewerASCIIPrintf(viewer,"%+gi",(double)eigi[i]);CHKERRQ(ierr); }
     325             : #endif
     326           1 :       ierr = PetscViewerASCIIPrintf(viewer," (%10.8e)\n",(double)errest[i]);CHKERRQ(ierr);
     327           1 :       ierr = PetscViewerASCIIUseTabs(viewer,PETSC_TRUE);CHKERRQ(ierr);
     328             :     }
     329           1 :     ierr = PetscViewerASCIISubtractTab(viewer,((PetscObject)nep)->tablevel);CHKERRQ(ierr);
     330           1 :     ierr = PetscViewerPopFormat(viewer);CHKERRQ(ierr);
     331           1 :     ctx->oldnconv = nconv;
     332             :   }
     333           6 :   PetscFunctionReturn(0);
     334             : }
     335             : 
     336           1 : PetscErrorCode NEPMonitorConvergedCreate(PetscViewer viewer,PetscViewerFormat format,void *ctx,PetscViewerAndFormat **vf)
     337             : {
     338           1 :   PetscErrorCode ierr;
     339           1 :   SlepcConvMon   mctx;
     340             : 
     341           1 :   PetscFunctionBegin;
     342           1 :   ierr = PetscViewerAndFormatCreate(viewer,format,vf);CHKERRQ(ierr);
     343           1 :   ierr = PetscNew(&mctx);CHKERRQ(ierr);
     344           1 :   mctx->ctx = ctx;
     345           1 :   (*vf)->data = (void*)mctx;
     346           1 :   PetscFunctionReturn(0);
     347             : }
     348             : 
     349           1 : PetscErrorCode NEPMonitorConvergedDestroy(PetscViewerAndFormat **vf)
     350             : {
     351           1 :   PetscErrorCode ierr;
     352             : 
     353           1 :   PetscFunctionBegin;
     354           1 :   if (!*vf) PetscFunctionReturn(0);
     355           1 :   ierr = PetscFree((*vf)->data);CHKERRQ(ierr);
     356           1 :   ierr = PetscViewerDestroy(&(*vf)->viewer);CHKERRQ(ierr);
     357           1 :   ierr = PetscDrawLGDestroy(&(*vf)->lg);CHKERRQ(ierr);
     358           1 :   ierr = PetscFree(*vf);CHKERRQ(ierr);
     359           1 :   PetscFunctionReturn(0);
     360             : }
     361             : 
     362             : /*@C
     363             :    NEPMonitorFirstDrawLG - Plots the error estimate of the first unconverged
     364             :    approximation at each iteration of the nonlinear eigensolver.
     365             : 
     366             :    Collective on nep
     367             : 
     368             :    Input Parameters:
     369             : +  nep    - nonlinear eigensolver context
     370             : .  its    - iteration number
     371             : .  its    - iteration number
     372             : .  nconv  - number of converged eigenpairs so far
     373             : .  eigr   - real part of the eigenvalues
     374             : .  eigi   - imaginary part of the eigenvalues
     375             : .  errest - error estimates
     376             : .  nest   - number of error estimates to display
     377             : -  vf     - viewer and format for monitoring
     378             : 
     379             :    Options Database Key:
     380             : .  -nep_monitor draw::draw_lg - activates NEPMonitorFirstDrawLG()
     381             : 
     382             :    Level: intermediate
     383             : 
     384             : .seealso: NEPMonitorSet()
     385             : @*/
     386          13 : PetscErrorCode NEPMonitorFirstDrawLG(NEP nep,PetscInt its,PetscInt nconv,PetscScalar *eigr,PetscScalar *eigi,PetscReal *errest,PetscInt nest,PetscViewerAndFormat *vf)
     387             : {
     388          13 :   PetscErrorCode ierr;
     389          13 :   PetscViewer    viewer = vf->viewer;
     390          13 :   PetscDrawLG    lg = vf->lg;
     391          13 :   PetscReal      x,y;
     392             : 
     393          13 :   PetscFunctionBegin;
     394          13 :   PetscValidHeaderSpecific(nep,NEP_CLASSID,1);
     395          13 :   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,8);
     396          13 :   PetscValidHeaderSpecific(lg,PETSC_DRAWLG_CLASSID,8);
     397          13 :   ierr = PetscViewerPushFormat(viewer,vf->format);CHKERRQ(ierr);
     398          13 :   if (its==1) {
     399           2 :     ierr = PetscDrawLGReset(lg);CHKERRQ(ierr);
     400           2 :     ierr = PetscDrawLGSetDimension(lg,1);CHKERRQ(ierr);
     401           2 :     ierr = PetscDrawLGSetLimits(lg,1,1,PetscLog10Real(nep->tol)-2,0.0);CHKERRQ(ierr);
     402             :   }
     403          13 :   if (nconv<nest) {
     404          12 :     x = (PetscReal)its;
     405          12 :     if (errest[nconv] > 0.0) y = PetscLog10Real(errest[nconv]);
     406           0 :     else y = 0.0;
     407          12 :     ierr = PetscDrawLGAddPoint(lg,&x,&y);CHKERRQ(ierr);
     408          12 :     if (its <= 20 || !(its % 5) || nep->reason) {
     409          12 :       ierr = PetscDrawLGDraw(lg);CHKERRQ(ierr);
     410          12 :       ierr = PetscDrawLGSave(lg);CHKERRQ(ierr);
     411             :     }
     412             :   }
     413          13 :   ierr = PetscViewerPopFormat(viewer);CHKERRQ(ierr);
     414          13 :   PetscFunctionReturn(0);
     415             : }
     416             : 
     417             : /*@C
     418             :    NEPMonitorFirstDrawLGCreate - Creates the plotter for the first error estimate.
     419             : 
     420             :    Collective on viewer
     421             : 
     422             :    Input Parameters:
     423             : +  viewer - the viewer
     424             : .  format - the viewer format
     425             : -  ctx    - an optional user context
     426             : 
     427             :    Output Parameter:
     428             : .  vf     - the viewer and format context
     429             : 
     430             :    Level: intermediate
     431             : 
     432             : .seealso: NEPMonitorSet()
     433             : @*/
     434           2 : PetscErrorCode NEPMonitorFirstDrawLGCreate(PetscViewer viewer,PetscViewerFormat format,void *ctx,PetscViewerAndFormat **vf)
     435             : {
     436           2 :   PetscErrorCode ierr;
     437             : 
     438           2 :   PetscFunctionBegin;
     439           2 :   ierr = PetscViewerAndFormatCreate(viewer,format,vf);CHKERRQ(ierr);
     440           2 :   (*vf)->data = ctx;
     441           2 :   ierr = NEPMonitorLGCreate(PetscObjectComm((PetscObject)viewer),NULL,"First Error Estimate","Log Error Estimate",1,NULL,PETSC_DECIDE,PETSC_DECIDE,400,300,&(*vf)->lg);CHKERRQ(ierr);
     442           2 :   PetscFunctionReturn(0);
     443             : }
     444             : 
     445             : /*@C
     446             :    NEPMonitorAllDrawLG - Plots the error estimate of all unconverged
     447             :    approximations at each iteration of the nonlinear eigensolver.
     448             : 
     449             :    Collective on nep
     450             : 
     451             :    Input Parameters:
     452             : +  nep    - nonlinear eigensolver context
     453             : .  its    - iteration number
     454             : .  its    - iteration number
     455             : .  nconv  - number of converged eigenpairs so far
     456             : .  eigr   - real part of the eigenvalues
     457             : .  eigi   - imaginary part of the eigenvalues
     458             : .  errest - error estimates
     459             : .  nest   - number of error estimates to display
     460             : -  vf     - viewer and format for monitoring
     461             : 
     462             :    Options Database Key:
     463             : .  -nep_monitor_all draw::draw_lg - activates NEPMonitorAllDrawLG()
     464             : 
     465             :    Level: intermediate
     466             : 
     467             : .seealso: NEPMonitorSet()
     468             : @*/
     469          12 : PetscErrorCode NEPMonitorAllDrawLG(NEP nep,PetscInt its,PetscInt nconv,PetscScalar *eigr,PetscScalar *eigi,PetscReal *errest,PetscInt nest,PetscViewerAndFormat *vf)
     470             : {
     471          12 :   PetscErrorCode ierr;
     472          12 :   PetscViewer    viewer = vf->viewer;
     473          12 :   PetscDrawLG    lg = vf->lg;
     474          12 :   PetscInt       i,n = PetscMin(nep->nev,255);
     475          12 :   PetscReal      *x,*y;
     476             : 
     477          12 :   PetscFunctionBegin;
     478          12 :   PetscValidHeaderSpecific(nep,NEP_CLASSID,1);
     479          12 :   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,8);
     480          12 :   PetscValidHeaderSpecific(lg,PETSC_DRAWLG_CLASSID,8);
     481          12 :   ierr = PetscViewerPushFormat(viewer,vf->format);CHKERRQ(ierr);
     482          12 :   if (its==1) {
     483           1 :     ierr = PetscDrawLGReset(lg);CHKERRQ(ierr);
     484           1 :     ierr = PetscDrawLGSetDimension(lg,n);CHKERRQ(ierr);
     485           1 :     ierr = PetscDrawLGSetLimits(lg,1,1,PetscLog10Real(nep->tol)-2,0.0);CHKERRQ(ierr);
     486             :   }
     487          12 :   ierr = PetscMalloc2(n,&x,n,&y);CHKERRQ(ierr);
     488          60 :   for (i=0;i<n;i++) {
     489          48 :     x[i] = (PetscReal)its;
     490          48 :     if (i < nest && errest[i] > 0.0) y[i] = PetscLog10Real(errest[i]);
     491          18 :     else y[i] = 0.0;
     492             :   }
     493          12 :   ierr = PetscDrawLGAddPoint(lg,x,y);CHKERRQ(ierr);
     494          12 :   if (its <= 20 || !(its % 5) || nep->reason) {
     495          12 :     ierr = PetscDrawLGDraw(lg);CHKERRQ(ierr);
     496          12 :     ierr = PetscDrawLGSave(lg);CHKERRQ(ierr);
     497             :   }
     498          12 :   ierr = PetscFree2(x,y);CHKERRQ(ierr);
     499          12 :   ierr = PetscViewerPopFormat(viewer);CHKERRQ(ierr);
     500          12 :   PetscFunctionReturn(0);
     501             : }
     502             : 
     503             : /*@C
     504             :    NEPMonitorAllDrawLGCreate - Creates the plotter for all the error estimates.
     505             : 
     506             :    Collective on viewer
     507             : 
     508             :    Input Parameters:
     509             : +  viewer - the viewer
     510             : .  format - the viewer format
     511             : -  ctx    - an optional user context
     512             : 
     513             :    Output Parameter:
     514             : .  vf     - the viewer and format context
     515             : 
     516             :    Level: intermediate
     517             : 
     518             : .seealso: NEPMonitorSet()
     519             : @*/
     520           1 : PetscErrorCode NEPMonitorAllDrawLGCreate(PetscViewer viewer,PetscViewerFormat format,void *ctx,PetscViewerAndFormat **vf)
     521             : {
     522           1 :   PetscErrorCode ierr;
     523             : 
     524           1 :   PetscFunctionBegin;
     525           1 :   ierr = PetscViewerAndFormatCreate(viewer,format,vf);CHKERRQ(ierr);
     526           1 :   (*vf)->data = ctx;
     527           1 :   ierr = NEPMonitorLGCreate(PetscObjectComm((PetscObject)viewer),NULL,"All Error Estimates","Log Error Estimate",1,NULL,PETSC_DECIDE,PETSC_DECIDE,400,300,&(*vf)->lg);CHKERRQ(ierr);
     528           1 :   PetscFunctionReturn(0);
     529             : }
     530             : 
     531             : /*@C
     532             :    NEPMonitorConvergedDrawLG - Plots the number of converged eigenvalues
     533             :    at each iteration of the nonlinear eigensolver.
     534             : 
     535             :    Collective on nep
     536             : 
     537             :    Input Parameters:
     538             : +  nep    - nonlinear eigensolver context
     539             : .  its    - iteration number
     540             : .  its    - iteration number
     541             : .  nconv  - number of converged eigenpairs so far
     542             : .  eigr   - real part of the eigenvalues
     543             : .  eigi   - imaginary part of the eigenvalues
     544             : .  errest - error estimates
     545             : .  nest   - number of error estimates to display
     546             : -  vf     - viewer and format for monitoring
     547             : 
     548             :    Options Database Key:
     549             : .  -nep_monitor_conv draw::draw_lg - activates NEPMonitorConvergedDrawLG()
     550             : 
     551             :    Level: intermediate
     552             : 
     553             : .seealso: NEPMonitorSet()
     554             : @*/
     555           0 : PetscErrorCode NEPMonitorConvergedDrawLG(NEP nep,PetscInt its,PetscInt nconv,PetscScalar *eigr,PetscScalar *eigi,PetscReal *errest,PetscInt nest,PetscViewerAndFormat *vf)
     556             : {
     557           0 :   PetscErrorCode   ierr;
     558           0 :   PetscViewer      viewer = vf->viewer;
     559           0 :   PetscDrawLG      lg = vf->lg;
     560           0 :   PetscReal        x,y;
     561             : 
     562           0 :   PetscFunctionBegin;
     563           0 :   PetscValidHeaderSpecific(nep,NEP_CLASSID,1);
     564           0 :   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,8);
     565           0 :   PetscValidHeaderSpecific(lg,PETSC_DRAWLG_CLASSID,8);
     566           0 :   ierr = PetscViewerPushFormat(viewer,vf->format);CHKERRQ(ierr);
     567           0 :   if (its==1) {
     568           0 :     ierr = PetscDrawLGReset(lg);CHKERRQ(ierr);
     569           0 :     ierr = PetscDrawLGSetDimension(lg,1);CHKERRQ(ierr);
     570           0 :     ierr = PetscDrawLGSetLimits(lg,1,1,0,nep->nev);CHKERRQ(ierr);
     571             :   }
     572           0 :   x = (PetscReal)its;
     573           0 :   y = (PetscReal)nep->nconv;
     574           0 :   ierr = PetscDrawLGAddPoint(lg,&x,&y);CHKERRQ(ierr);
     575           0 :   if (its <= 20 || !(its % 5) || nep->reason) {
     576           0 :     ierr = PetscDrawLGDraw(lg);CHKERRQ(ierr);
     577           0 :     ierr = PetscDrawLGSave(lg);CHKERRQ(ierr);
     578             :   }
     579           0 :   ierr = PetscViewerPopFormat(viewer);CHKERRQ(ierr);
     580           0 :   PetscFunctionReturn(0);
     581             : }
     582             : 
     583             : /*@C
     584             :    NEPMonitorConvergedDrawLGCreate - Creates the plotter for the convergence history.
     585             : 
     586             :    Collective on viewer
     587             : 
     588             :    Input Parameters:
     589             : +  viewer - the viewer
     590             : .  format - the viewer format
     591             : -  ctx    - an optional user context
     592             : 
     593             :    Output Parameter:
     594             : .  vf     - the viewer and format context
     595             : 
     596             :    Level: intermediate
     597             : 
     598             : .seealso: NEPMonitorSet()
     599             : @*/
     600           0 : PetscErrorCode NEPMonitorConvergedDrawLGCreate(PetscViewer viewer,PetscViewerFormat format,void *ctx,PetscViewerAndFormat **vf)
     601             : {
     602           0 :   PetscErrorCode ierr;
     603           0 :   SlepcConvMon   mctx;
     604             : 
     605           0 :   PetscFunctionBegin;
     606           0 :   ierr = PetscViewerAndFormatCreate(viewer,format,vf);CHKERRQ(ierr);
     607           0 :   ierr = PetscNew(&mctx);CHKERRQ(ierr);
     608           0 :   mctx->ctx = ctx;
     609           0 :   (*vf)->data = (void*)mctx;
     610           0 :   ierr = NEPMonitorLGCreate(PetscObjectComm((PetscObject)viewer),NULL,"Convergence History","Number Converged",1,NULL,PETSC_DECIDE,PETSC_DECIDE,400,300,&(*vf)->lg);CHKERRQ(ierr);
     611           0 :   PetscFunctionReturn(0);
     612             : }
     613             : 

Generated by: LCOV version 1.14