LCOV - code coverage report
Current view: top level - nep/interface - nepview.c (source / functions) Hit Total Coverage
Test: SLEPc Lines: 355 418 84.9 %
Date: 2021-08-02 00:35:43 Functions: 17 17 100.0 %
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 various viewers
      12             : */
      13             : 
      14             : #include <slepc/private/nepimpl.h>      /*I "slepcnep.h" I*/
      15             : #include <slepc/private/bvimpl.h>       /*I "slepcbv.h" I*/
      16             : #include <petscdraw.h>
      17             : 
      18             : /*@C
      19             :    NEPView - Prints the NEP data structure.
      20             : 
      21             :    Collective on nep
      22             : 
      23             :    Input Parameters:
      24             : +  nep - the nonlinear eigenproblem solver context
      25             : -  viewer - optional visualization context
      26             : 
      27             :    Options Database Key:
      28             : .  -nep_view -  Calls NEPView() at end of NEPSolve()
      29             : 
      30             :    Note:
      31             :    The available visualization contexts include
      32             : +     PETSC_VIEWER_STDOUT_SELF - standard output (default)
      33             : -     PETSC_VIEWER_STDOUT_WORLD - synchronized standard
      34             :          output where only the first processor opens
      35             :          the file.  All other processors send their
      36             :          data to the first processor to print.
      37             : 
      38             :    The user can open an alternative visualization context with
      39             :    PetscViewerASCIIOpen() - output to a specified file.
      40             : 
      41             :    Level: beginner
      42             : @*/
      43           3 : PetscErrorCode NEPView(NEP nep,PetscViewer viewer)
      44             : {
      45           3 :   PetscErrorCode ierr;
      46           3 :   const char     *type=NULL;
      47           3 :   char           str[50];
      48           3 :   PetscInt       i;
      49           3 :   PetscBool      isascii,istrivial;
      50           3 :   PetscViewer    sviewer;
      51             : 
      52           3 :   PetscFunctionBegin;
      53           3 :   PetscValidHeaderSpecific(nep,NEP_CLASSID,1);
      54           3 :   if (!viewer) {
      55           0 :     ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)nep),&viewer);CHKERRQ(ierr);
      56             :   }
      57           3 :   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,2);
      58           3 :   PetscCheckSameComm(nep,1,viewer,2);
      59             : 
      60           3 :   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&isascii);CHKERRQ(ierr);
      61           3 :   if (isascii) {
      62           3 :     ierr = PetscObjectPrintClassNamePrefixType((PetscObject)nep,viewer);CHKERRQ(ierr);
      63           3 :     if (nep->ops->view) {
      64           3 :       ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
      65           3 :       ierr = (*nep->ops->view)(nep,viewer);CHKERRQ(ierr);
      66           3 :       ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
      67             :     }
      68           3 :     if (nep->problem_type) {
      69           3 :       switch (nep->problem_type) {
      70           3 :         case NEP_GENERAL:  type = "general nonlinear eigenvalue problem"; break;
      71           0 :         case NEP_RATIONAL: type = "rational eigenvalue problem"; break;
      72             :       }
      73             :     } else type = "not yet set";
      74           3 :     ierr = PetscViewerASCIIPrintf(viewer,"  problem type: %s\n",type);CHKERRQ(ierr);
      75           3 :     if (nep->fui) {
      76           3 :       switch (nep->fui) {
      77           0 :       case NEP_USER_INTERFACE_CALLBACK:
      78           0 :         ierr = PetscViewerASCIIPrintf(viewer,"  nonlinear operator from user callbacks\n");CHKERRQ(ierr);
      79             :         break;
      80           3 :       case NEP_USER_INTERFACE_SPLIT:
      81           3 :         ierr = PetscViewerASCIIPrintf(viewer,"  nonlinear operator in split form, with %D terms\n",nep->nt);CHKERRQ(ierr);
      82             :         break;
      83             :       }
      84             :     } else {
      85           0 :       ierr = PetscViewerASCIIPrintf(viewer,"  nonlinear operator not specified yet\n");CHKERRQ(ierr);
      86             :     }
      87           3 :     ierr = PetscViewerASCIIPrintf(viewer,"  selected portion of the spectrum: ");CHKERRQ(ierr);
      88           3 :     ierr = PetscViewerASCIIUseTabs(viewer,PETSC_FALSE);CHKERRQ(ierr);
      89           3 :     ierr = SlepcSNPrintfScalar(str,sizeof(str),nep->target,PETSC_FALSE);CHKERRQ(ierr);
      90           3 :     if (!nep->which) {
      91           0 :       ierr = PetscViewerASCIIPrintf(viewer,"not yet set\n");CHKERRQ(ierr);
      92           3 :     } else switch (nep->which) {
      93           0 :       case NEP_WHICH_USER:
      94           0 :         ierr = PetscViewerASCIIPrintf(viewer,"user defined\n");CHKERRQ(ierr);
      95             :         break;
      96           3 :       case NEP_TARGET_MAGNITUDE:
      97           3 :         ierr = PetscViewerASCIIPrintf(viewer,"closest to target: %s (in magnitude)\n",str);CHKERRQ(ierr);
      98             :         break;
      99           0 :       case NEP_TARGET_REAL:
     100           0 :         ierr = PetscViewerASCIIPrintf(viewer,"closest to target: %s (along the real axis)\n",str);CHKERRQ(ierr);
     101             :         break;
     102           0 :       case NEP_TARGET_IMAGINARY:
     103           0 :         ierr = PetscViewerASCIIPrintf(viewer,"closest to target: %s (along the imaginary axis)\n",str);CHKERRQ(ierr);
     104             :         break;
     105           0 :       case NEP_LARGEST_MAGNITUDE:
     106           0 :         ierr = PetscViewerASCIIPrintf(viewer,"largest eigenvalues in magnitude\n");CHKERRQ(ierr);
     107             :         break;
     108           0 :       case NEP_SMALLEST_MAGNITUDE:
     109           0 :         ierr = PetscViewerASCIIPrintf(viewer,"smallest eigenvalues in magnitude\n");CHKERRQ(ierr);
     110             :         break;
     111           0 :       case NEP_LARGEST_REAL:
     112           0 :         ierr = PetscViewerASCIIPrintf(viewer,"largest real parts\n");CHKERRQ(ierr);
     113             :         break;
     114           0 :       case NEP_SMALLEST_REAL:
     115           0 :         ierr = PetscViewerASCIIPrintf(viewer,"smallest real parts\n");CHKERRQ(ierr);
     116             :         break;
     117           0 :       case NEP_LARGEST_IMAGINARY:
     118           0 :         ierr = PetscViewerASCIIPrintf(viewer,"largest imaginary parts\n");CHKERRQ(ierr);
     119             :         break;
     120           0 :       case NEP_SMALLEST_IMAGINARY:
     121           0 :         ierr = PetscViewerASCIIPrintf(viewer,"smallest imaginary parts\n");CHKERRQ(ierr);
     122             :         break;
     123           0 :       case NEP_ALL:
     124           0 :         ierr = PetscViewerASCIIPrintf(viewer,"all eigenvalues in the region\n");CHKERRQ(ierr);
     125             :         break;
     126             :     }
     127           3 :     ierr = PetscViewerASCIIUseTabs(viewer,PETSC_TRUE);CHKERRQ(ierr);
     128           3 :     if (nep->twosided) {
     129           0 :       ierr = PetscViewerASCIIPrintf(viewer,"  using two-sided variant (for left eigenvectors)\n");CHKERRQ(ierr);
     130             :     }
     131           3 :     ierr = PetscViewerASCIIPrintf(viewer,"  number of eigenvalues (nev): %D\n",nep->nev);CHKERRQ(ierr);
     132           3 :     ierr = PetscViewerASCIIPrintf(viewer,"  number of column vectors (ncv): %D\n",nep->ncv);CHKERRQ(ierr);
     133           3 :     ierr = PetscViewerASCIIPrintf(viewer,"  maximum dimension of projected problem (mpd): %D\n",nep->mpd);CHKERRQ(ierr);
     134           3 :     ierr = PetscViewerASCIIPrintf(viewer,"  maximum number of iterations: %D\n",nep->max_it);CHKERRQ(ierr);
     135           3 :     ierr = PetscViewerASCIIPrintf(viewer,"  tolerance: %g\n",(double)nep->tol);CHKERRQ(ierr);
     136           3 :     ierr = PetscViewerASCIIPrintf(viewer,"  convergence test: ");CHKERRQ(ierr);
     137           3 :     ierr = PetscViewerASCIIUseTabs(viewer,PETSC_FALSE);CHKERRQ(ierr);
     138           3 :     switch (nep->conv) {
     139           0 :     case NEP_CONV_ABS:
     140           0 :       ierr = PetscViewerASCIIPrintf(viewer,"absolute\n");CHKERRQ(ierr);break;
     141           0 :     case NEP_CONV_REL:
     142           0 :       ierr = PetscViewerASCIIPrintf(viewer,"relative to the eigenvalue\n");CHKERRQ(ierr);break;
     143           3 :     case NEP_CONV_NORM:
     144           3 :       ierr = PetscViewerASCIIPrintf(viewer,"relative to the matrix norms\n");CHKERRQ(ierr);
     145           3 :       if (nep->nrma) {
     146           3 :         ierr = PetscViewerASCIIPrintf(viewer,"  computed matrix norms: %g",(double)nep->nrma[0]);CHKERRQ(ierr);
     147           8 :         for (i=1;i<nep->nt;i++) {
     148           5 :           ierr = PetscViewerASCIIPrintf(viewer,", %g",(double)nep->nrma[i]);CHKERRQ(ierr);
     149             :         }
     150           3 :         ierr = PetscViewerASCIIPrintf(viewer,"\n");CHKERRQ(ierr);
     151             :       }
     152             :       break;
     153           0 :     case NEP_CONV_USER:
     154           0 :       ierr = PetscViewerASCIIPrintf(viewer,"user-defined\n");CHKERRQ(ierr);break;
     155             :     }
     156           3 :     ierr = PetscViewerASCIIUseTabs(viewer,PETSC_TRUE);CHKERRQ(ierr);
     157           3 :     if (nep->refine) {
     158           0 :       ierr = PetscViewerASCIIPrintf(viewer,"  iterative refinement: %s, with %s scheme\n",NEPRefineTypes[nep->refine],NEPRefineSchemes[nep->scheme]);CHKERRQ(ierr);
     159           0 :       ierr = PetscViewerASCIIPrintf(viewer,"  refinement stopping criterion: tol=%g, its=%D\n",(double)nep->rtol,nep->rits);CHKERRQ(ierr);
     160           0 :       if (nep->npart>1) {
     161           0 :         ierr = PetscViewerASCIIPrintf(viewer,"  splitting communicator in %D partitions for refinement\n",nep->npart);CHKERRQ(ierr);
     162             :       }
     163             :     }
     164           3 :     if (nep->nini) {
     165           1 :       ierr = PetscViewerASCIIPrintf(viewer,"  dimension of user-provided initial space: %D\n",PetscAbs(nep->nini));CHKERRQ(ierr);
     166             :     }
     167             :   } else {
     168           0 :     if (nep->ops->view) {
     169           0 :       ierr = (*nep->ops->view)(nep,viewer);CHKERRQ(ierr);
     170             :     }
     171             :   }
     172           3 :   ierr = PetscViewerPushFormat(viewer,PETSC_VIEWER_ASCII_INFO);CHKERRQ(ierr);
     173           3 :   if (!nep->V) { ierr = NEPGetBV(nep,&nep->V);CHKERRQ(ierr); }
     174           3 :   ierr = BVView(nep->V,viewer);CHKERRQ(ierr);
     175           3 :   if (!nep->rg) { ierr = NEPGetRG(nep,&nep->rg);CHKERRQ(ierr); }
     176           3 :   ierr = RGIsTrivial(nep->rg,&istrivial);CHKERRQ(ierr);
     177           3 :   if (!istrivial) { ierr = RGView(nep->rg,viewer);CHKERRQ(ierr); }
     178           3 :   if (nep->useds) {
     179           3 :     if (!nep->ds) { ierr = NEPGetDS(nep,&nep->ds);CHKERRQ(ierr); }
     180           3 :     ierr = DSView(nep->ds,viewer);CHKERRQ(ierr);
     181             :   }
     182           3 :   ierr = PetscViewerPopFormat(viewer);CHKERRQ(ierr);
     183           3 :   if (nep->refine!=NEP_REFINE_NONE) {
     184           0 :     ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
     185           0 :     if (nep->npart>1) {
     186           0 :       if (nep->refinesubc->color==0) {
     187           0 :         ierr = PetscViewerASCIIGetStdout(PetscSubcommChild(nep->refinesubc),&sviewer);CHKERRQ(ierr);
     188           0 :         ierr = KSPView(nep->refineksp,sviewer);CHKERRQ(ierr);
     189             :       }
     190             :     } else {
     191           0 :       ierr = KSPView(nep->refineksp,viewer);CHKERRQ(ierr);
     192             :     }
     193           0 :     ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
     194             :   }
     195           3 :   PetscFunctionReturn(0);
     196             : }
     197             : 
     198             : /*@C
     199             :    NEPViewFromOptions - View from options
     200             : 
     201             :    Collective on NEP
     202             : 
     203             :    Input Parameters:
     204             : +  nep  - the nonlinear eigensolver context
     205             : .  obj  - optional object
     206             : -  name - command line option
     207             : 
     208             :    Level: intermediate
     209             : 
     210             : .seealso: NEPView(), NEPCreate()
     211             : @*/
     212         246 : PetscErrorCode NEPViewFromOptions(NEP nep,PetscObject obj,const char name[])
     213             : {
     214         246 :   PetscErrorCode ierr;
     215             : 
     216         246 :   PetscFunctionBegin;
     217         246 :   PetscValidHeaderSpecific(nep,NEP_CLASSID,1);
     218         246 :   ierr = PetscObjectViewFromOptions((PetscObject)nep,obj,name);CHKERRQ(ierr);
     219         246 :   PetscFunctionReturn(0);
     220             : }
     221             : 
     222             : /*@C
     223             :    NEPConvergedReasonView - Displays the reason a NEP solve converged or diverged.
     224             : 
     225             :    Collective on nep
     226             : 
     227             :    Input Parameters:
     228             : +  nep - the nonlinear eigensolver context
     229             : -  viewer - the viewer to display the reason
     230             : 
     231             :    Options Database Keys:
     232             : .  -nep_converged_reason - print reason for convergence, and number of iterations
     233             : 
     234             :    Note:
     235             :    To change the format of the output call PetscViewerPushFormat(viewer,format) before
     236             :    this call. Use PETSC_VIEWER_DEFAULT for the default, use PETSC_VIEWER_FAILED to only
     237             :    display a reason if it fails. The latter can be set in the command line with
     238             :    -nep_converged_reason ::failed
     239             : 
     240             :    Level: intermediate
     241             : 
     242             : .seealso: NEPSetConvergenceTest(), NEPSetTolerances(), NEPGetIterationNumber(), NEPConvergedReasonViewFromOptions(
     243             : @*/
     244           2 : PetscErrorCode NEPConvergedReasonView(NEP nep,PetscViewer viewer)
     245             : {
     246           2 :   PetscErrorCode    ierr;
     247           2 :   PetscBool         isAscii;
     248           2 :   PetscViewerFormat format;
     249             : 
     250           2 :   PetscFunctionBegin;
     251           2 :   if (!viewer) viewer = PETSC_VIEWER_STDOUT_(PetscObjectComm((PetscObject)nep));
     252           2 :   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&isAscii);CHKERRQ(ierr);
     253           2 :   if (isAscii) {
     254           2 :     ierr = PetscViewerGetFormat(viewer,&format);CHKERRQ(ierr);
     255           2 :     ierr = PetscViewerASCIIAddTab(viewer,((PetscObject)nep)->tablevel);CHKERRQ(ierr);
     256           2 :     if (nep->reason > 0 && format != PETSC_VIEWER_FAILED) {
     257           3 :       ierr = PetscViewerASCIIPrintf(viewer,"%s Nonlinear eigensolve converged (%D eigenpair%s) due to %s; iterations %D\n",((PetscObject)nep)->prefix?((PetscObject)nep)->prefix:"",nep->nconv,(nep->nconv>1)?"s":"",NEPConvergedReasons[nep->reason],nep->its);CHKERRQ(ierr);
     258           0 :     } else if (nep->reason <= 0) {
     259           0 :       ierr = PetscViewerASCIIPrintf(viewer,"%s Nonlinear eigensolve did not converge due to %s; iterations %D\n",((PetscObject)nep)->prefix?((PetscObject)nep)->prefix:"",NEPConvergedReasons[nep->reason],nep->its);CHKERRQ(ierr);
     260             :     }
     261           2 :     ierr = PetscViewerASCIISubtractTab(viewer,((PetscObject)nep)->tablevel);CHKERRQ(ierr);
     262             :   }
     263           2 :   PetscFunctionReturn(0);
     264             : }
     265             : 
     266             : /*@
     267             :    NEPConvergedReasonViewFromOptions - Processes command line options to determine if/how
     268             :    the NEP converged reason is to be viewed.
     269             : 
     270             :    Collective on nep
     271             : 
     272             :    Input Parameter:
     273             : .  nep - the nonlinear eigensolver context
     274             : 
     275             :    Level: developer
     276             : 
     277             : .seealso: NEPConvergedReasonView()
     278             : @*/
     279         123 : PetscErrorCode NEPConvergedReasonViewFromOptions(NEP nep)
     280             : {
     281         123 :   PetscErrorCode    ierr;
     282         123 :   PetscViewer       viewer;
     283         123 :   PetscBool         flg;
     284         123 :   static PetscBool  incall = PETSC_FALSE;
     285         123 :   PetscViewerFormat format;
     286             : 
     287         123 :   PetscFunctionBegin;
     288         123 :   if (incall) PetscFunctionReturn(0);
     289         123 :   incall = PETSC_TRUE;
     290         123 :   ierr = PetscOptionsGetViewer(PetscObjectComm((PetscObject)nep),((PetscObject)nep)->options,((PetscObject)nep)->prefix,"-nep_converged_reason",&viewer,&format,&flg);CHKERRQ(ierr);
     291         123 :   if (flg) {
     292           1 :     ierr = PetscViewerPushFormat(viewer,format);CHKERRQ(ierr);
     293           1 :     ierr = NEPConvergedReasonView(nep,viewer);CHKERRQ(ierr);
     294           1 :     ierr = PetscViewerPopFormat(viewer);CHKERRQ(ierr);
     295           1 :     ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
     296             :   }
     297         123 :   incall = PETSC_FALSE;
     298         123 :   PetscFunctionReturn(0);
     299             : }
     300             : 
     301         116 : static PetscErrorCode NEPErrorView_ASCII(NEP nep,NEPErrorType etype,PetscViewer viewer)
     302             : {
     303         116 :   PetscReal      error;
     304         116 :   PetscInt       i,j,k,nvals;
     305         116 :   PetscErrorCode ierr;
     306             : 
     307         116 :   PetscFunctionBegin;
     308         116 :   nvals = (nep->which==NEP_ALL)? nep->nconv: nep->nev;
     309         116 :   if (nep->which!=NEP_ALL && nep->nconv<nvals) {
     310           0 :     ierr = PetscViewerASCIIPrintf(viewer," Problem: less than %D eigenvalues converged\n\n",nep->nev);CHKERRQ(ierr);
     311           0 :     PetscFunctionReturn(0);
     312             :   }
     313         116 :   if (nep->which==NEP_ALL && !nvals) {
     314           0 :     ierr = PetscViewerASCIIPrintf(viewer," No eigenvalues have been found\n\n");CHKERRQ(ierr);
     315           0 :     PetscFunctionReturn(0);
     316             :   }
     317         493 :   for (i=0;i<nvals;i++) {
     318         377 :     ierr = NEPComputeError(nep,i,etype,&error);CHKERRQ(ierr);
     319         377 :     if (error>=5.0*nep->tol) {
     320           0 :       ierr = PetscViewerASCIIPrintf(viewer," Problem: some of the first %D relative errors are higher than the tolerance\n\n",nvals);CHKERRQ(ierr);
     321         377 :       PetscFunctionReturn(0);
     322             :     }
     323             :   }
     324         116 :   if (nep->which==NEP_ALL) {
     325          25 :     ierr = PetscViewerASCIIPrintf(viewer," Found %D eigenvalues, all of them computed up to the required tolerance:",nvals);CHKERRQ(ierr);
     326             :   } else {
     327          91 :     ierr = PetscViewerASCIIPrintf(viewer," All requested eigenvalues computed up to the required tolerance:");CHKERRQ(ierr);
     328             :   }
     329         235 :   for (i=0;i<=(nvals-1)/8;i++) {
     330         119 :     ierr = PetscViewerASCIIPrintf(viewer,"\n     ");CHKERRQ(ierr);
     331         496 :     for (j=0;j<PetscMin(8,nvals-8*i);j++) {
     332         377 :       k = nep->perm[8*i+j];
     333         377 :       ierr = SlepcPrintEigenvalueASCII(viewer,nep->eigr[k],nep->eigi[k]);CHKERRQ(ierr);
     334         377 :       if (8*i+j+1<nvals) { ierr = PetscViewerASCIIPrintf(viewer,", ");CHKERRQ(ierr); }
     335             :     }
     336             :   }
     337         116 :   ierr = PetscViewerASCIIPrintf(viewer,"\n\n");CHKERRQ(ierr);
     338         116 :   PetscFunctionReturn(0);
     339             : }
     340             : 
     341           1 : static PetscErrorCode NEPErrorView_DETAIL(NEP nep,NEPErrorType etype,PetscViewer viewer)
     342             : {
     343           1 :   PetscErrorCode ierr;
     344           1 :   PetscReal      error,re,im;
     345           1 :   PetscScalar    kr,ki;
     346           1 :   PetscInt       i;
     347           1 :   char           ex[30],sep[]=" ---------------------- --------------------\n";
     348             : 
     349           1 :   PetscFunctionBegin;
     350           1 :   if (!nep->nconv) PetscFunctionReturn(0);
     351           1 :   switch (etype) {
     352           0 :     case NEP_ERROR_ABSOLUTE:
     353           0 :       ierr = PetscSNPrintf(ex,sizeof(ex),"    ||T(k)x||");CHKERRQ(ierr);
     354             :       break;
     355           0 :     case NEP_ERROR_RELATIVE:
     356           0 :       ierr = PetscSNPrintf(ex,sizeof(ex)," ||T(k)x||/||kx||");CHKERRQ(ierr);
     357             :       break;
     358           1 :     case NEP_ERROR_BACKWARD:
     359           1 :       ierr = PetscSNPrintf(ex,sizeof(ex),"    eta(x,k)");CHKERRQ(ierr);
     360             :       break;
     361             :   }
     362           1 :   ierr = PetscViewerASCIIPrintf(viewer,"%s            k             %s\n%s",sep,ex,sep);CHKERRQ(ierr);
     363           2 :   for (i=0;i<nep->nconv;i++) {
     364           1 :     ierr = NEPGetEigenpair(nep,i,&kr,&ki,NULL,NULL);CHKERRQ(ierr);
     365           1 :     ierr = NEPComputeError(nep,i,etype,&error);CHKERRQ(ierr);
     366             : #if defined(PETSC_USE_COMPLEX)
     367           1 :     re = PetscRealPart(kr);
     368           1 :     im = PetscImaginaryPart(kr);
     369             : #else
     370             :     re = kr;
     371             :     im = ki;
     372             : #endif
     373           1 :     if (im!=0.0) {
     374           1 :       ierr = PetscViewerASCIIPrintf(viewer,"  % 9f%+9fi      %12g\n",(double)re,(double)im,(double)error);CHKERRQ(ierr);
     375             :     } else {
     376           1 :       ierr = PetscViewerASCIIPrintf(viewer,"    % 12f           %12g\n",(double)re,(double)error);CHKERRQ(ierr);
     377             :     }
     378             :   }
     379           1 :   ierr = PetscViewerASCIIPrintf(viewer,sep);CHKERRQ(ierr);
     380           1 :   PetscFunctionReturn(0);
     381             : }
     382             : 
     383           2 : static PetscErrorCode NEPErrorView_MATLAB(NEP nep,NEPErrorType etype,PetscViewer viewer)
     384             : {
     385           2 :   PetscErrorCode ierr;
     386           2 :   PetscReal      error;
     387           2 :   PetscInt       i;
     388           2 :   const char     *name;
     389             : 
     390           2 :   PetscFunctionBegin;
     391           2 :   ierr = PetscObjectGetName((PetscObject)nep,&name);CHKERRQ(ierr);
     392           2 :   ierr = PetscViewerASCIIPrintf(viewer,"Error_%s = [\n",name);CHKERRQ(ierr);
     393           7 :   for (i=0;i<nep->nconv;i++) {
     394           5 :     ierr = NEPComputeError(nep,i,etype,&error);CHKERRQ(ierr);
     395           5 :     ierr = PetscViewerASCIIPrintf(viewer,"%18.16e\n",(double)error);CHKERRQ(ierr);
     396             :   }
     397           2 :   ierr = PetscViewerASCIIPrintf(viewer,"];\n");CHKERRQ(ierr);
     398           2 :   PetscFunctionReturn(0);
     399             : }
     400             : 
     401             : /*@C
     402             :    NEPErrorView - Displays the errors associated with the computed solution
     403             :    (as well as the eigenvalues).
     404             : 
     405             :    Collective on nep
     406             : 
     407             :    Input Parameters:
     408             : +  nep    - the nonlinear eigensolver context
     409             : .  etype  - error type
     410             : -  viewer - optional visualization context
     411             : 
     412             :    Options Database Key:
     413             : +  -nep_error_absolute - print absolute errors of each eigenpair
     414             : .  -nep_error_relative - print relative errors of each eigenpair
     415             : -  -nep_error_backward - print backward errors of each eigenpair
     416             : 
     417             :    Notes:
     418             :    By default, this function checks the error of all eigenpairs and prints
     419             :    the eigenvalues if all of them are below the requested tolerance.
     420             :    If the viewer has format=PETSC_VIEWER_ASCII_INFO_DETAIL then a table with
     421             :    eigenvalues and corresponding errors is printed.
     422             : 
     423             :    Level: intermediate
     424             : 
     425             : .seealso: NEPSolve(), NEPValuesView(), NEPVectorsView()
     426             : @*/
     427         119 : PetscErrorCode NEPErrorView(NEP nep,NEPErrorType etype,PetscViewer viewer)
     428             : {
     429         119 :   PetscBool         isascii;
     430         119 :   PetscViewerFormat format;
     431         119 :   PetscErrorCode    ierr;
     432             : 
     433         119 :   PetscFunctionBegin;
     434         119 :   PetscValidHeaderSpecific(nep,NEP_CLASSID,1);
     435         119 :   if (!viewer) {
     436         116 :     ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)nep),&viewer);CHKERRQ(ierr);
     437             :   }
     438         119 :   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,3);
     439         119 :   PetscCheckSameComm(nep,1,viewer,3);
     440         119 :   NEPCheckSolved(nep,1);
     441         119 :   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&isascii);CHKERRQ(ierr);
     442         119 :   if (!isascii) PetscFunctionReturn(0);
     443             : 
     444         119 :   ierr = PetscViewerGetFormat(viewer,&format);CHKERRQ(ierr);
     445         119 :   switch (format) {
     446         116 :     case PETSC_VIEWER_DEFAULT:
     447             :     case PETSC_VIEWER_ASCII_INFO:
     448         116 :       ierr = NEPErrorView_ASCII(nep,etype,viewer);CHKERRQ(ierr);
     449             :       break;
     450           1 :     case PETSC_VIEWER_ASCII_INFO_DETAIL:
     451           1 :       ierr = NEPErrorView_DETAIL(nep,etype,viewer);CHKERRQ(ierr);
     452             :       break;
     453           2 :     case PETSC_VIEWER_ASCII_MATLAB:
     454           2 :       ierr = NEPErrorView_MATLAB(nep,etype,viewer);CHKERRQ(ierr);
     455             :       break;
     456           0 :     default:
     457           0 :       ierr = PetscInfo1(nep,"Unsupported viewer format %s\n",PetscViewerFormats[format]);CHKERRQ(ierr);
     458             :   }
     459         119 :   PetscFunctionReturn(0);
     460             : }
     461             : 
     462             : /*@
     463             :    NEPErrorViewFromOptions - Processes command line options to determine if/how
     464             :    the errors of the computed solution are to be viewed.
     465             : 
     466             :    Collective on nep
     467             : 
     468             :    Input Parameter:
     469             : .  nep - the nonlinear eigensolver context
     470             : 
     471             :    Level: developer
     472             : @*/
     473         123 : PetscErrorCode NEPErrorViewFromOptions(NEP nep)
     474             : {
     475         123 :   PetscErrorCode    ierr;
     476         123 :   PetscViewer       viewer;
     477         123 :   PetscBool         flg;
     478         123 :   static PetscBool  incall = PETSC_FALSE;
     479         123 :   PetscViewerFormat format;
     480             : 
     481         123 :   PetscFunctionBegin;
     482         123 :   if (incall) PetscFunctionReturn(0);
     483         123 :   incall = PETSC_TRUE;
     484         123 :   ierr = PetscOptionsGetViewer(PetscObjectComm((PetscObject)nep),((PetscObject)nep)->options,((PetscObject)nep)->prefix,"-nep_error_absolute",&viewer,&format,&flg);CHKERRQ(ierr);
     485         123 :   if (flg) {
     486           1 :     ierr = PetscViewerPushFormat(viewer,format);CHKERRQ(ierr);
     487           1 :     ierr = NEPErrorView(nep,NEP_ERROR_ABSOLUTE,viewer);CHKERRQ(ierr);
     488           1 :     ierr = PetscViewerPopFormat(viewer);CHKERRQ(ierr);
     489           1 :     ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
     490             :   }
     491         123 :   ierr = PetscOptionsGetViewer(PetscObjectComm((PetscObject)nep),((PetscObject)nep)->options,((PetscObject)nep)->prefix,"-nep_error_relative",&viewer,&format,&flg);CHKERRQ(ierr);
     492         123 :   if (flg) {
     493           1 :     ierr = PetscViewerPushFormat(viewer,format);CHKERRQ(ierr);
     494           1 :     ierr = NEPErrorView(nep,NEP_ERROR_RELATIVE,viewer);CHKERRQ(ierr);
     495           1 :     ierr = PetscViewerPopFormat(viewer);CHKERRQ(ierr);
     496           1 :     ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
     497             :   }
     498         123 :   ierr = PetscOptionsGetViewer(PetscObjectComm((PetscObject)nep),((PetscObject)nep)->options,((PetscObject)nep)->prefix,"-nep_error_backward",&viewer,&format,&flg);CHKERRQ(ierr);
     499         123 :   if (flg) {
     500           1 :     ierr = PetscViewerPushFormat(viewer,format);CHKERRQ(ierr);
     501           1 :     ierr = NEPErrorView(nep,NEP_ERROR_BACKWARD,viewer);CHKERRQ(ierr);
     502           1 :     ierr = PetscViewerPopFormat(viewer);CHKERRQ(ierr);
     503           1 :     ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
     504             :   }
     505         123 :   incall = PETSC_FALSE;
     506         123 :   PetscFunctionReturn(0);
     507             : }
     508             : 
     509           2 : static PetscErrorCode NEPValuesView_DRAW(NEP nep,PetscViewer viewer)
     510             : {
     511           2 :   PetscErrorCode ierr;
     512           2 :   PetscDraw      draw;
     513           2 :   PetscDrawSP    drawsp;
     514           2 :   PetscReal      re,im;
     515           2 :   PetscInt       i,k;
     516             : 
     517           2 :   PetscFunctionBegin;
     518           2 :   if (!nep->nconv) PetscFunctionReturn(0);
     519           2 :   ierr = PetscViewerDrawGetDraw(viewer,0,&draw);CHKERRQ(ierr);
     520           2 :   ierr = PetscDrawSetTitle(draw,"Computed Eigenvalues");CHKERRQ(ierr);
     521           2 :   ierr = PetscDrawSPCreate(draw,1,&drawsp);CHKERRQ(ierr);
     522           9 :   for (i=0;i<nep->nconv;i++) {
     523           7 :     k = nep->perm[i];
     524             : #if defined(PETSC_USE_COMPLEX)
     525           7 :     re = PetscRealPart(nep->eigr[k]);
     526           7 :     im = PetscImaginaryPart(nep->eigr[k]);
     527             : #else
     528             :     re = nep->eigr[k];
     529             :     im = nep->eigi[k];
     530             : #endif
     531           7 :     ierr = PetscDrawSPAddPoint(drawsp,&re,&im);CHKERRQ(ierr);
     532             :   }
     533           2 :   ierr = PetscDrawSPDraw(drawsp,PETSC_TRUE);CHKERRQ(ierr);
     534           2 :   ierr = PetscDrawSPSave(drawsp);CHKERRQ(ierr);
     535           2 :   ierr = PetscDrawSPDestroy(&drawsp);CHKERRQ(ierr);
     536           2 :   PetscFunctionReturn(0);
     537             : }
     538             : 
     539           1 : static PetscErrorCode NEPValuesView_BINARY(NEP nep,PetscViewer viewer)
     540             : {
     541             : #if defined(PETSC_HAVE_COMPLEX)
     542           1 :   PetscInt       i,k;
     543           1 :   PetscComplex   *ev;
     544           1 :   PetscErrorCode ierr;
     545             : #endif
     546             : 
     547           1 :   PetscFunctionBegin;
     548             : #if defined(PETSC_HAVE_COMPLEX)
     549           1 :   ierr = PetscMalloc1(nep->nconv,&ev);CHKERRQ(ierr);
     550           5 :   for (i=0;i<nep->nconv;i++) {
     551           4 :     k = nep->perm[i];
     552             : #if defined(PETSC_USE_COMPLEX)
     553           4 :     ev[i] = nep->eigr[k];
     554             : #else
     555             :     ev[i] = PetscCMPLX(nep->eigr[k],nep->eigi[k]);
     556             : #endif
     557             :   }
     558           1 :   ierr = PetscViewerBinaryWrite(viewer,ev,nep->nconv,PETSC_COMPLEX);CHKERRQ(ierr);
     559           1 :   ierr = PetscFree(ev);CHKERRQ(ierr);
     560             : #endif
     561           1 :   PetscFunctionReturn(0);
     562             : }
     563             : 
     564             : #if defined(PETSC_HAVE_HDF5)
     565             : static PetscErrorCode NEPValuesView_HDF5(NEP nep,PetscViewer viewer)
     566             : {
     567             :   PetscErrorCode ierr;
     568             :   PetscInt       i,k,n,N;
     569             :   PetscMPIInt    rank;
     570             :   Vec            v;
     571             :   char           vname[30];
     572             :   const char     *ename;
     573             : 
     574             :   PetscFunctionBegin;
     575             :   ierr = MPI_Comm_rank(PetscObjectComm((PetscObject)nep),&rank);CHKERRMPI(ierr);
     576             :   N = nep->nconv;
     577             :   n = rank? 0: N;
     578             :   /* create a vector containing the eigenvalues */
     579             :   ierr = VecCreateMPI(PetscObjectComm((PetscObject)nep),n,N,&v);CHKERRQ(ierr);
     580             :   ierr = PetscObjectGetName((PetscObject)nep,&ename);CHKERRQ(ierr);
     581             :   ierr = PetscSNPrintf(vname,sizeof(vname),"eigr_%s",ename);CHKERRQ(ierr);
     582             :   ierr = PetscObjectSetName((PetscObject)v,vname);CHKERRQ(ierr);
     583             :   if (!rank) {
     584             :     for (i=0;i<nep->nconv;i++) {
     585             :       k = nep->perm[i];
     586             :       ierr = VecSetValue(v,i,nep->eigr[k],INSERT_VALUES);CHKERRQ(ierr);
     587             :     }
     588             :   }
     589             :   ierr = VecAssemblyBegin(v);CHKERRQ(ierr);
     590             :   ierr = VecAssemblyEnd(v);CHKERRQ(ierr);
     591             :   ierr = VecView(v,viewer);CHKERRQ(ierr);
     592             : #if !defined(PETSC_USE_COMPLEX)
     593             :   /* in real scalars write the imaginary part as a separate vector */
     594             :   ierr = PetscSNPrintf(vname,sizeof(vname),"eigi_%s",ename);CHKERRQ(ierr);
     595             :   ierr = PetscObjectSetName((PetscObject)v,vname);CHKERRQ(ierr);
     596             :   if (!rank) {
     597             :     for (i=0;i<nep->nconv;i++) {
     598             :       k = nep->perm[i];
     599             :       ierr = VecSetValue(v,i,nep->eigi[k],INSERT_VALUES);CHKERRQ(ierr);
     600             :     }
     601             :   }
     602             :   ierr = VecAssemblyBegin(v);CHKERRQ(ierr);
     603             :   ierr = VecAssemblyEnd(v);CHKERRQ(ierr);
     604             :   ierr = VecView(v,viewer);CHKERRQ(ierr);
     605             : #endif
     606             :   ierr = VecDestroy(&v);CHKERRQ(ierr);
     607             :   PetscFunctionReturn(0);
     608             : }
     609             : #endif
     610             : 
     611           1 : static PetscErrorCode NEPValuesView_ASCII(NEP nep,PetscViewer viewer)
     612             : {
     613           1 :   PetscInt       i,k;
     614           1 :   PetscErrorCode ierr;
     615             : 
     616           1 :   PetscFunctionBegin;
     617           1 :   ierr = PetscViewerASCIIPrintf(viewer,"Eigenvalues = \n");CHKERRQ(ierr);
     618           2 :   for (i=0;i<nep->nconv;i++) {
     619           1 :     k = nep->perm[i];
     620           1 :     ierr = PetscViewerASCIIPrintf(viewer,"   ");CHKERRQ(ierr);
     621           1 :     ierr = SlepcPrintEigenvalueASCII(viewer,nep->eigr[k],nep->eigi[k]);CHKERRQ(ierr);
     622           1 :     ierr = PetscViewerASCIIPrintf(viewer,"\n");CHKERRQ(ierr);
     623             :   }
     624           1 :   ierr = PetscViewerASCIIPrintf(viewer,"\n");CHKERRQ(ierr);
     625           1 :   PetscFunctionReturn(0);
     626             : }
     627             : 
     628           1 : static PetscErrorCode NEPValuesView_MATLAB(NEP nep,PetscViewer viewer)
     629             : {
     630           1 :   PetscErrorCode ierr;
     631           1 :   PetscInt       i,k;
     632           1 :   PetscReal      re,im;
     633           1 :   const char     *name;
     634             : 
     635           1 :   PetscFunctionBegin;
     636           1 :   ierr = PetscObjectGetName((PetscObject)nep,&name);CHKERRQ(ierr);
     637           1 :   ierr = PetscViewerASCIIPrintf(viewer,"Lambda_%s = [\n",name);CHKERRQ(ierr);
     638           2 :   for (i=0;i<nep->nconv;i++) {
     639           1 :     k = nep->perm[i];
     640             : #if defined(PETSC_USE_COMPLEX)
     641           1 :     re = PetscRealPart(nep->eigr[k]);
     642           1 :     im = PetscImaginaryPart(nep->eigr[k]);
     643             : #else
     644             :     re = nep->eigr[k];
     645             :     im = nep->eigi[k];
     646             : #endif
     647           1 :     if (im!=0.0) {
     648           1 :       ierr = PetscViewerASCIIPrintf(viewer,"%18.16e%+18.16ei\n",(double)re,(double)im);CHKERRQ(ierr);
     649             :     } else {
     650           1 :       ierr = PetscViewerASCIIPrintf(viewer,"%18.16e\n",(double)re);CHKERRQ(ierr);
     651             :     }
     652             :   }
     653           1 :   ierr = PetscViewerASCIIPrintf(viewer,"];\n");CHKERRQ(ierr);
     654           1 :   PetscFunctionReturn(0);
     655             : }
     656             : 
     657             : /*@C
     658             :    NEPValuesView - Displays the computed eigenvalues in a viewer.
     659             : 
     660             :    Collective on nep
     661             : 
     662             :    Input Parameters:
     663             : +  nep    - the nonlinear eigensolver context
     664             : -  viewer - the viewer
     665             : 
     666             :    Options Database Key:
     667             : .  -nep_view_values - print computed eigenvalues
     668             : 
     669             :    Level: intermediate
     670             : 
     671             : .seealso: NEPSolve(), NEPVectorsView(), NEPErrorView()
     672             : @*/
     673           5 : PetscErrorCode NEPValuesView(NEP nep,PetscViewer viewer)
     674             : {
     675           5 :   PetscBool         isascii,isdraw,isbinary;
     676           5 :   PetscViewerFormat format;
     677           5 :   PetscErrorCode    ierr;
     678             : #if defined(PETSC_HAVE_HDF5)
     679             :   PetscBool         ishdf5;
     680             : #endif
     681             : 
     682           5 :   PetscFunctionBegin;
     683           5 :   PetscValidHeaderSpecific(nep,NEP_CLASSID,1);
     684           5 :   if (!viewer) {
     685           0 :     ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)nep),&viewer);CHKERRQ(ierr);
     686             :   }
     687           5 :   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,2);
     688           5 :   PetscCheckSameComm(nep,1,viewer,2);
     689           5 :   NEPCheckSolved(nep,1);
     690           5 :   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
     691           5 :   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERBINARY,&isbinary);CHKERRQ(ierr);
     692             : #if defined(PETSC_HAVE_HDF5)
     693             :   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERHDF5,&ishdf5);CHKERRQ(ierr);
     694             : #endif
     695           5 :   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&isascii);CHKERRQ(ierr);
     696           5 :   if (isdraw) {
     697           2 :     ierr = NEPValuesView_DRAW(nep,viewer);CHKERRQ(ierr);
     698           3 :   } else if (isbinary) {
     699           1 :     ierr = NEPValuesView_BINARY(nep,viewer);CHKERRQ(ierr);
     700             : #if defined(PETSC_HAVE_HDF5)
     701             :   } else if (ishdf5) {
     702             :     ierr = NEPValuesView_HDF5(nep,viewer);CHKERRQ(ierr);
     703             : #endif
     704           2 :   } else if (isascii) {
     705           2 :     ierr = PetscViewerGetFormat(viewer,&format);CHKERRQ(ierr);
     706           2 :     switch (format) {
     707           1 :       case PETSC_VIEWER_DEFAULT:
     708             :       case PETSC_VIEWER_ASCII_INFO:
     709             :       case PETSC_VIEWER_ASCII_INFO_DETAIL:
     710           1 :         ierr = NEPValuesView_ASCII(nep,viewer);CHKERRQ(ierr);
     711             :         break;
     712           1 :       case PETSC_VIEWER_ASCII_MATLAB:
     713           1 :         ierr = NEPValuesView_MATLAB(nep,viewer);CHKERRQ(ierr);
     714             :         break;
     715           0 :       default:
     716           0 :         ierr = PetscInfo1(nep,"Unsupported viewer format %s\n",PetscViewerFormats[format]);CHKERRQ(ierr);
     717             :     }
     718             :   }
     719           5 :   PetscFunctionReturn(0);
     720             : }
     721             : 
     722             : /*@
     723             :    NEPValuesViewFromOptions - Processes command line options to determine if/how
     724             :    the computed eigenvalues are to be viewed.
     725             : 
     726             :    Collective on nep
     727             : 
     728             :    Input Parameter:
     729             : .  nep - the nonlinear eigensolver context
     730             : 
     731             :    Level: developer
     732             : @*/
     733         123 : PetscErrorCode NEPValuesViewFromOptions(NEP nep)
     734             : {
     735         123 :   PetscErrorCode    ierr;
     736         123 :   PetscViewer       viewer;
     737         123 :   PetscBool         flg;
     738         123 :   static PetscBool  incall = PETSC_FALSE;
     739         123 :   PetscViewerFormat format;
     740             : 
     741         123 :   PetscFunctionBegin;
     742         123 :   if (incall) PetscFunctionReturn(0);
     743         123 :   incall = PETSC_TRUE;
     744         123 :   ierr = PetscOptionsGetViewer(PetscObjectComm((PetscObject)nep),((PetscObject)nep)->options,((PetscObject)nep)->prefix,"-nep_view_values",&viewer,&format,&flg);CHKERRQ(ierr);
     745         123 :   if (flg) {
     746           5 :     ierr = PetscViewerPushFormat(viewer,format);CHKERRQ(ierr);
     747           5 :     ierr = NEPValuesView(nep,viewer);CHKERRQ(ierr);
     748           5 :     ierr = PetscViewerPopFormat(viewer);CHKERRQ(ierr);
     749           5 :     ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
     750             :   }
     751         123 :   incall = PETSC_FALSE;
     752         123 :   PetscFunctionReturn(0);
     753             : }
     754             : 
     755             : /*@C
     756             :    NEPVectorsView - Outputs computed eigenvectors to a viewer.
     757             : 
     758             :    Collective on nep
     759             : 
     760             :    Input Parameters:
     761             : +  nep    - the nonlinear eigensolver context
     762             : -  viewer - the viewer
     763             : 
     764             :    Options Database Keys:
     765             : .  -nep_view_vectors - output eigenvectors.
     766             : 
     767             :    Notes:
     768             :    If PETSc was configured with real scalars, complex conjugate eigenvectors
     769             :    will be viewed as two separate real vectors, one containing the real part
     770             :    and another one containing the imaginary part.
     771             : 
     772             :    If left eigenvectors were computed with a two-sided eigensolver, the right
     773             :    and left eigenvectors are interleaved, that is, the vectors are output in
     774             :    the following order: X0, Y0, X1, Y1, X2, Y2, ...
     775             : 
     776             :    Level: intermediate
     777             : 
     778             : .seealso: NEPSolve(), NEPValuesView(), NEPErrorView()
     779             : @*/
     780           3 : PetscErrorCode NEPVectorsView(NEP nep,PetscViewer viewer)
     781             : {
     782           3 :   PetscErrorCode ierr;
     783           3 :   PetscInt       i,k;
     784           3 :   Vec            xr,xi=NULL;
     785             : 
     786           3 :   PetscFunctionBegin;
     787           3 :   PetscValidHeaderSpecific(nep,NEP_CLASSID,1);
     788           3 :   if (!viewer) {
     789           0 :     ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)nep),&viewer);CHKERRQ(ierr);
     790             :   }
     791           3 :   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,2);
     792           3 :   PetscCheckSameComm(nep,1,viewer,2);
     793           3 :   NEPCheckSolved(nep,1);
     794           3 :   if (nep->nconv) {
     795           3 :     ierr = NEPComputeVectors(nep);CHKERRQ(ierr);
     796           3 :     ierr = BVCreateVec(nep->V,&xr);CHKERRQ(ierr);
     797             : #if !defined(PETSC_USE_COMPLEX)
     798             :     ierr = BVCreateVec(nep->V,&xi);CHKERRQ(ierr);
     799             : #endif
     800           6 :     for (i=0;i<nep->nconv;i++) {
     801           3 :       k = nep->perm[i];
     802           3 :       ierr = BV_GetEigenvector(nep->V,k,nep->eigi[k],xr,xi);CHKERRQ(ierr);
     803           3 :       ierr = SlepcViewEigenvector(viewer,xr,xi,"X",i,(PetscObject)nep);CHKERRQ(ierr);
     804           3 :       if (nep->twosided) {
     805           1 :         ierr = BV_GetEigenvector(nep->W,k,nep->eigi[k],xr,xi);CHKERRQ(ierr);
     806           3 :         ierr = SlepcViewEigenvector(viewer,xr,xi,"Y",i,(PetscObject)nep);CHKERRQ(ierr);
     807             :       }
     808             :     }
     809           3 :     ierr = VecDestroy(&xr);CHKERRQ(ierr);
     810             : #if !defined(PETSC_USE_COMPLEX)
     811             :     ierr = VecDestroy(&xi);CHKERRQ(ierr);
     812             : #endif
     813             :   }
     814           3 :   PetscFunctionReturn(0);
     815             : }
     816             : 
     817             : /*@
     818             :    NEPVectorsViewFromOptions - Processes command line options to determine if/how
     819             :    the computed eigenvectors are to be viewed.
     820             : 
     821             :    Collective on nep
     822             : 
     823             :    Input Parameter:
     824             : .  nep - the nonlinear eigensolver context
     825             : 
     826             :    Level: developer
     827             : @*/
     828         123 : PetscErrorCode NEPVectorsViewFromOptions(NEP nep)
     829             : {
     830         123 :   PetscErrorCode    ierr;
     831         123 :   PetscViewer       viewer;
     832         123 :   PetscBool         flg = PETSC_FALSE;
     833         123 :   static PetscBool  incall = PETSC_FALSE;
     834         123 :   PetscViewerFormat format;
     835             : 
     836         123 :   PetscFunctionBegin;
     837         123 :   if (incall) PetscFunctionReturn(0);
     838         123 :   incall = PETSC_TRUE;
     839         123 :   ierr = PetscOptionsGetViewer(PetscObjectComm((PetscObject)nep),((PetscObject)nep)->options,((PetscObject)nep)->prefix,"-nep_view_vectors",&viewer,&format,&flg);CHKERRQ(ierr);
     840         123 :   if (flg) {
     841           3 :     ierr = PetscViewerPushFormat(viewer,format);CHKERRQ(ierr);
     842           3 :     ierr = NEPVectorsView(nep,viewer);CHKERRQ(ierr);
     843           3 :     ierr = PetscViewerPopFormat(viewer);CHKERRQ(ierr);
     844           3 :     ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
     845             :   }
     846         123 :   incall = PETSC_FALSE;
     847         123 :   PetscFunctionReturn(0);
     848             : }
     849             : 

Generated by: LCOV version 1.14