LCOV - code coverage report
Current view: top level - nep/interface - nepbasic.c (source / functions) Hit Total Coverage
Test: SLEPc Lines: 342 373 91.7 %
Date: 2021-08-02 00:35:43 Functions: 21 24 87.5 %
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             :    Basic NEP routines
      12             : */
      13             : 
      14             : #include <slepc/private/nepimpl.h>      /*I "slepcnep.h" I*/
      15             : 
      16             : /* Logging support */
      17             : PetscClassId      NEP_CLASSID = 0;
      18             : PetscLogEvent     NEP_SetUp = 0,NEP_Solve = 0,NEP_Refine = 0,NEP_FunctionEval = 0,NEP_JacobianEval = 0,NEP_Resolvent = 0;
      19             : 
      20             : /* List of registered NEP routines */
      21             : PetscFunctionList NEPList = 0;
      22             : PetscBool         NEPRegisterAllCalled = PETSC_FALSE;
      23             : 
      24             : /* List of registered NEP monitors */
      25             : PetscFunctionList NEPMonitorList              = NULL;
      26             : PetscFunctionList NEPMonitorCreateList        = NULL;
      27             : PetscFunctionList NEPMonitorDestroyList       = NULL;
      28             : PetscBool         NEPMonitorRegisterAllCalled = PETSC_FALSE;
      29             : 
      30             : /*@
      31             :    NEPCreate - Creates the default NEP context.
      32             : 
      33             :    Collective
      34             : 
      35             :    Input Parameter:
      36             : .  comm - MPI communicator
      37             : 
      38             :    Output Parameter:
      39             : .  nep - location to put the NEP context
      40             : 
      41             :    Level: beginner
      42             : 
      43             : .seealso: NEPSetUp(), NEPSolve(), NEPDestroy(), NEP
      44             : @*/
      45         110 : PetscErrorCode NEPCreate(MPI_Comm comm,NEP *outnep)
      46             : {
      47         110 :   PetscErrorCode ierr;
      48         110 :   NEP            nep;
      49             : 
      50         110 :   PetscFunctionBegin;
      51         110 :   PetscValidPointer(outnep,2);
      52         110 :   *outnep = 0;
      53         110 :   ierr = NEPInitializePackage();CHKERRQ(ierr);
      54         110 :   ierr = SlepcHeaderCreate(nep,NEP_CLASSID,"NEP","Nonlinear Eigenvalue Problem","NEP",comm,NEPDestroy,NEPView);CHKERRQ(ierr);
      55             : 
      56         110 :   nep->max_it          = PETSC_DEFAULT;
      57         110 :   nep->nev             = 1;
      58         110 :   nep->ncv             = PETSC_DEFAULT;
      59         110 :   nep->mpd             = PETSC_DEFAULT;
      60         110 :   nep->nini            = 0;
      61         110 :   nep->target          = 0.0;
      62         110 :   nep->tol             = PETSC_DEFAULT;
      63         110 :   nep->conv            = NEP_CONV_NORM;
      64         110 :   nep->stop            = NEP_STOP_BASIC;
      65         110 :   nep->which           = (NEPWhich)0;
      66         110 :   nep->problem_type    = (NEPProblemType)0;
      67         110 :   nep->refine          = NEP_REFINE_NONE;
      68         110 :   nep->npart           = 1;
      69         110 :   nep->rtol            = PETSC_DEFAULT;
      70         110 :   nep->rits            = PETSC_DEFAULT;
      71         110 :   nep->scheme          = (NEPRefineScheme)0;
      72         110 :   nep->trackall        = PETSC_FALSE;
      73         110 :   nep->twosided        = PETSC_FALSE;
      74             : 
      75         110 :   nep->computefunction = NULL;
      76         110 :   nep->computejacobian = NULL;
      77         110 :   nep->functionctx     = NULL;
      78         110 :   nep->jacobianctx     = NULL;
      79         110 :   nep->converged       = NEPConvergedRelative;
      80         110 :   nep->convergeduser   = NULL;
      81         110 :   nep->convergeddestroy= NULL;
      82         110 :   nep->stopping        = NEPStoppingBasic;
      83         110 :   nep->stoppinguser    = NULL;
      84         110 :   nep->stoppingdestroy = NULL;
      85         110 :   nep->convergedctx    = NULL;
      86         110 :   nep->stoppingctx     = NULL;
      87         110 :   nep->numbermonitors  = 0;
      88             : 
      89         110 :   nep->ds              = NULL;
      90         110 :   nep->V               = NULL;
      91         110 :   nep->W               = NULL;
      92         110 :   nep->rg              = NULL;
      93         110 :   nep->function        = NULL;
      94         110 :   nep->function_pre    = NULL;
      95         110 :   nep->jacobian        = NULL;
      96         110 :   nep->A               = NULL;
      97         110 :   nep->f               = NULL;
      98         110 :   nep->nt              = 0;
      99         110 :   nep->mstr            = UNKNOWN_NONZERO_PATTERN;
     100         110 :   nep->IS              = NULL;
     101         110 :   nep->eigr            = NULL;
     102         110 :   nep->eigi            = NULL;
     103         110 :   nep->errest          = NULL;
     104         110 :   nep->perm            = NULL;
     105         110 :   nep->nwork           = 0;
     106         110 :   nep->work            = NULL;
     107         110 :   nep->data            = NULL;
     108             : 
     109         110 :   nep->state           = NEP_STATE_INITIAL;
     110         110 :   nep->nconv           = 0;
     111         110 :   nep->its             = 0;
     112         110 :   nep->n               = 0;
     113         110 :   nep->nloc            = 0;
     114         110 :   nep->nrma            = NULL;
     115         110 :   nep->fui             = (NEPUserInterface)0;
     116         110 :   nep->useds           = PETSC_FALSE;
     117         110 :   nep->resolvent       = NULL;
     118         110 :   nep->reason          = NEP_CONVERGED_ITERATING;
     119             : 
     120         110 :   ierr = PetscNewLog(nep,&nep->sc);CHKERRQ(ierr);
     121         110 :   *outnep = nep;
     122         110 :   PetscFunctionReturn(0);
     123             : }
     124             : 
     125             : /*@C
     126             :    NEPSetType - Selects the particular solver to be used in the NEP object.
     127             : 
     128             :    Logically Collective on nep
     129             : 
     130             :    Input Parameters:
     131             : +  nep      - the nonlinear eigensolver context
     132             : -  type     - a known method
     133             : 
     134             :    Options Database Key:
     135             : .  -nep_type <method> - Sets the method; use -help for a list
     136             :     of available methods
     137             : 
     138             :    Notes:
     139             :    See "slepc/include/slepcnep.h" for available methods.
     140             : 
     141             :    Normally, it is best to use the NEPSetFromOptions() command and
     142             :    then set the NEP type from the options database rather than by using
     143             :    this routine.  Using the options database provides the user with
     144             :    maximum flexibility in evaluating the different available methods.
     145             :    The NEPSetType() routine is provided for those situations where it
     146             :    is necessary to set the iterative solver independently of the command
     147             :    line or options database.
     148             : 
     149             :    Level: intermediate
     150             : 
     151             : .seealso: NEPType
     152             : @*/
     153         121 : PetscErrorCode NEPSetType(NEP nep,NEPType type)
     154             : {
     155         121 :   PetscErrorCode ierr,(*r)(NEP);
     156         121 :   PetscBool      match;
     157             : 
     158         121 :   PetscFunctionBegin;
     159         121 :   PetscValidHeaderSpecific(nep,NEP_CLASSID,1);
     160         121 :   PetscValidCharPointer(type,2);
     161             : 
     162         121 :   ierr = PetscObjectTypeCompare((PetscObject)nep,type,&match);CHKERRQ(ierr);
     163         121 :   if (match) PetscFunctionReturn(0);
     164             : 
     165         120 :   ierr = PetscFunctionListFind(NEPList,type,&r);CHKERRQ(ierr);
     166         120 :   if (!r) SETERRQ1(PetscObjectComm((PetscObject)nep),PETSC_ERR_ARG_UNKNOWN_TYPE,"Unknown NEP type given: %s",type);
     167             : 
     168         120 :   if (nep->ops->destroy) { ierr = (*nep->ops->destroy)(nep);CHKERRQ(ierr); }
     169         120 :   ierr = PetscMemzero(nep->ops,sizeof(struct _NEPOps));CHKERRQ(ierr);
     170             : 
     171         120 :   nep->state = NEP_STATE_INITIAL;
     172         120 :   ierr = PetscObjectChangeTypeName((PetscObject)nep,type);CHKERRQ(ierr);
     173         120 :   ierr = (*r)(nep);CHKERRQ(ierr);
     174         120 :   PetscFunctionReturn(0);
     175             : }
     176             : 
     177             : /*@C
     178             :    NEPGetType - Gets the NEP type as a string from the NEP object.
     179             : 
     180             :    Not Collective
     181             : 
     182             :    Input Parameter:
     183             : .  nep - the eigensolver context
     184             : 
     185             :    Output Parameter:
     186             : .  name - name of NEP method
     187             : 
     188             :    Level: intermediate
     189             : 
     190             : .seealso: NEPSetType()
     191             : @*/
     192          22 : PetscErrorCode NEPGetType(NEP nep,NEPType *type)
     193             : {
     194          22 :   PetscFunctionBegin;
     195          22 :   PetscValidHeaderSpecific(nep,NEP_CLASSID,1);
     196          22 :   PetscValidPointer(type,2);
     197          22 :   *type = ((PetscObject)nep)->type_name;
     198          22 :   PetscFunctionReturn(0);
     199             : }
     200             : 
     201             : /*@C
     202             :    NEPRegister - Adds a method to the nonlinear eigenproblem solver package.
     203             : 
     204             :    Not Collective
     205             : 
     206             :    Input Parameters:
     207             : +  name - name of a new user-defined solver
     208             : -  function - routine to create the solver context
     209             : 
     210             :    Notes:
     211             :    NEPRegister() may be called multiple times to add several user-defined solvers.
     212             : 
     213             :    Sample usage:
     214             : .vb
     215             :     NEPRegister("my_solver",MySolverCreate);
     216             : .ve
     217             : 
     218             :    Then, your solver can be chosen with the procedural interface via
     219             : $     NEPSetType(nep,"my_solver")
     220             :    or at runtime via the option
     221             : $     -nep_type my_solver
     222             : 
     223             :    Level: advanced
     224             : 
     225             : .seealso: NEPRegisterAll()
     226             : @*/
     227         666 : PetscErrorCode NEPRegister(const char *name,PetscErrorCode (*function)(NEP))
     228             : {
     229         666 :   PetscErrorCode ierr;
     230             : 
     231         666 :   PetscFunctionBegin;
     232         666 :   ierr = NEPInitializePackage();CHKERRQ(ierr);
     233         666 :   ierr = PetscFunctionListAdd(&NEPList,name,function);CHKERRQ(ierr);
     234         666 :   PetscFunctionReturn(0);
     235             : }
     236             : 
     237             : /*@C
     238             :    NEPMonitorRegister - Adds NEP monitor routine.
     239             : 
     240             :    Not Collective
     241             : 
     242             :    Input Parameters:
     243             : +  name    - name of a new monitor routine
     244             : .  vtype   - a PetscViewerType for the output
     245             : .  format  - a PetscViewerFormat for the output
     246             : .  monitor - monitor routine
     247             : .  create  - creation routine, or NULL
     248             : -  destroy - destruction routine, or NULL
     249             : 
     250             :    Notes:
     251             :    NEPMonitorRegister() may be called multiple times to add several user-defined monitors.
     252             : 
     253             :    Sample usage:
     254             : .vb
     255             :    NEPMonitorRegister("my_monitor",PETSCVIEWERASCII,PETSC_VIEWER_ASCII_INFO_DETAIL,MyMonitor,NULL,NULL);
     256             : .ve
     257             : 
     258             :    Then, your monitor can be chosen with the procedural interface via
     259             : $      NEPMonitorSetFromOptions(nep,"-nep_monitor_my_monitor","my_monitor",NULL)
     260             :    or at runtime via the option
     261             : $      -nep_monitor_my_monitor
     262             : 
     263             :    Level: advanced
     264             : 
     265             : .seealso: NEPMonitorRegisterAll()
     266             : @*/
     267         666 : PetscErrorCode NEPMonitorRegister(const char name[],PetscViewerType vtype,PetscViewerFormat format,PetscErrorCode (*monitor)(NEP,PetscInt,PetscInt,PetscScalar*,PetscScalar*,PetscReal*,PetscInt,PetscViewerAndFormat*),PetscErrorCode (*create)(PetscViewer,PetscViewerFormat,void*,PetscViewerAndFormat**),PetscErrorCode (*destroy)(PetscViewerAndFormat**))
     268             : {
     269         666 :   char           key[PETSC_MAX_PATH_LEN];
     270         666 :   PetscErrorCode ierr;
     271             : 
     272         666 :   PetscFunctionBegin;
     273         666 :   ierr = NEPInitializePackage();CHKERRQ(ierr);
     274         666 :   ierr = SlepcMonitorMakeKey_Internal(name,vtype,format,key);CHKERRQ(ierr);
     275         666 :   ierr = PetscFunctionListAdd(&NEPMonitorList,key,monitor);CHKERRQ(ierr);
     276         666 :   if (create)  { ierr = PetscFunctionListAdd(&NEPMonitorCreateList,key,create);CHKERRQ(ierr); }
     277         666 :   if (destroy) { ierr = PetscFunctionListAdd(&NEPMonitorDestroyList,key,destroy);CHKERRQ(ierr); }
     278         666 :   PetscFunctionReturn(0);
     279             : }
     280             : 
     281             : /*
     282             :    NEPReset_Problem - Destroys the problem matrices.
     283             : @*/
     284         215 : PetscErrorCode NEPReset_Problem(NEP nep)
     285             : {
     286         215 :   PetscErrorCode ierr;
     287         215 :   PetscInt       i;
     288             : 
     289         215 :   PetscFunctionBegin;
     290         215 :   PetscValidHeaderSpecific(nep,NEP_CLASSID,1);
     291         215 :   ierr = MatDestroy(&nep->function);CHKERRQ(ierr);
     292         215 :   ierr = MatDestroy(&nep->function_pre);CHKERRQ(ierr);
     293         215 :   ierr = MatDestroy(&nep->jacobian);CHKERRQ(ierr);
     294         215 :   if (nep->fui==NEP_USER_INTERFACE_SPLIT) {
     295         105 :     ierr = MatDestroyMatrices(nep->nt,&nep->A);CHKERRQ(ierr);
     296         409 :     for (i=0;i<nep->nt;i++) {
     297         304 :       ierr = FNDestroy(&nep->f[i]);CHKERRQ(ierr);
     298             :     }
     299         105 :     ierr = PetscFree(nep->f);CHKERRQ(ierr);
     300         105 :     ierr = PetscFree(nep->nrma);CHKERRQ(ierr);
     301         105 :     nep->nt = 0;
     302             :   }
     303         215 :   PetscFunctionReturn(0);
     304             : }
     305             : /*@
     306             :    NEPReset - Resets the NEP context to the initial state (prior to setup)
     307             :    and destroys any allocated Vecs and Mats.
     308             : 
     309             :    Collective on nep
     310             : 
     311             :    Input Parameter:
     312             : .  nep - eigensolver context obtained from NEPCreate()
     313             : 
     314             :    Level: advanced
     315             : 
     316             : .seealso: NEPDestroy()
     317             : @*/
     318         124 : PetscErrorCode NEPReset(NEP nep)
     319             : {
     320         124 :   PetscErrorCode ierr;
     321             : 
     322         124 :   PetscFunctionBegin;
     323         124 :   if (nep) PetscValidHeaderSpecific(nep,NEP_CLASSID,1);
     324         124 :   if (!nep) PetscFunctionReturn(0);
     325         124 :   if (nep->ops->reset) { ierr = (nep->ops->reset)(nep);CHKERRQ(ierr); }
     326         124 :   if (nep->refineksp) { ierr = KSPReset(nep->refineksp);CHKERRQ(ierr); }
     327         124 :   ierr = NEPReset_Problem(nep);CHKERRQ(ierr);
     328         124 :   ierr = BVDestroy(&nep->V);CHKERRQ(ierr);
     329         124 :   ierr = BVDestroy(&nep->W);CHKERRQ(ierr);
     330         124 :   ierr = VecDestroyVecs(nep->nwork,&nep->work);CHKERRQ(ierr);
     331         124 :   ierr = MatDestroy(&nep->resolvent);CHKERRQ(ierr);
     332         124 :   nep->nwork = 0;
     333         124 :   nep->state = NEP_STATE_INITIAL;
     334         124 :   PetscFunctionReturn(0);
     335             : }
     336             : 
     337             : /*@C
     338             :    NEPDestroy - Destroys the NEP context.
     339             : 
     340             :    Collective on nep
     341             : 
     342             :    Input Parameter:
     343             : .  nep - eigensolver context obtained from NEPCreate()
     344             : 
     345             :    Level: beginner
     346             : 
     347             : .seealso: NEPCreate(), NEPSetUp(), NEPSolve()
     348             : @*/
     349         110 : PetscErrorCode NEPDestroy(NEP *nep)
     350             : {
     351         110 :   PetscErrorCode ierr;
     352             : 
     353         110 :   PetscFunctionBegin;
     354         110 :   if (!*nep) PetscFunctionReturn(0);
     355         110 :   PetscValidHeaderSpecific(*nep,NEP_CLASSID,1);
     356         110 :   if (--((PetscObject)(*nep))->refct > 0) { *nep = 0; PetscFunctionReturn(0); }
     357         110 :   ierr = NEPReset(*nep);CHKERRQ(ierr);
     358         110 :   if ((*nep)->ops->destroy) { ierr = (*(*nep)->ops->destroy)(*nep);CHKERRQ(ierr); }
     359         110 :   if ((*nep)->eigr) {
     360         110 :     ierr = PetscFree4((*nep)->eigr,(*nep)->eigi,(*nep)->errest,(*nep)->perm);CHKERRQ(ierr);
     361             :   }
     362         110 :   ierr = RGDestroy(&(*nep)->rg);CHKERRQ(ierr);
     363         110 :   ierr = DSDestroy(&(*nep)->ds);CHKERRQ(ierr);
     364         110 :   ierr = KSPDestroy(&(*nep)->refineksp);CHKERRQ(ierr);
     365         110 :   ierr = PetscSubcommDestroy(&(*nep)->refinesubc);CHKERRQ(ierr);
     366         110 :   ierr = PetscFree((*nep)->sc);CHKERRQ(ierr);
     367             :   /* just in case the initial vectors have not been used */
     368         110 :   ierr = SlepcBasisDestroy_Private(&(*nep)->nini,&(*nep)->IS);CHKERRQ(ierr);
     369         110 :   if ((*nep)->convergeddestroy) {
     370           0 :     ierr = (*(*nep)->convergeddestroy)((*nep)->convergedctx);CHKERRQ(ierr);
     371             :   }
     372         110 :   ierr = NEPMonitorCancel(*nep);CHKERRQ(ierr);
     373         110 :   ierr = PetscHeaderDestroy(nep);CHKERRQ(ierr);
     374         110 :   PetscFunctionReturn(0);
     375             : }
     376             : 
     377             : /*@
     378             :    NEPSetBV - Associates a basis vectors object to the nonlinear eigensolver.
     379             : 
     380             :    Collective on nep
     381             : 
     382             :    Input Parameters:
     383             : +  nep - eigensolver context obtained from NEPCreate()
     384             : -  bv  - the basis vectors object
     385             : 
     386             :    Note:
     387             :    Use NEPGetBV() to retrieve the basis vectors context (for example,
     388             :    to free it at the end of the computations).
     389             : 
     390             :    Level: advanced
     391             : 
     392             : .seealso: NEPGetBV()
     393             : @*/
     394           0 : PetscErrorCode NEPSetBV(NEP nep,BV bv)
     395             : {
     396           0 :   PetscErrorCode ierr;
     397             : 
     398           0 :   PetscFunctionBegin;
     399           0 :   PetscValidHeaderSpecific(nep,NEP_CLASSID,1);
     400           0 :   PetscValidHeaderSpecific(bv,BV_CLASSID,2);
     401           0 :   PetscCheckSameComm(nep,1,bv,2);
     402           0 :   ierr = PetscObjectReference((PetscObject)bv);CHKERRQ(ierr);
     403           0 :   ierr = BVDestroy(&nep->V);CHKERRQ(ierr);
     404           0 :   nep->V = bv;
     405           0 :   ierr = PetscLogObjectParent((PetscObject)nep,(PetscObject)nep->V);CHKERRQ(ierr);
     406           0 :   PetscFunctionReturn(0);
     407             : }
     408             : 
     409             : /*@
     410             :    NEPGetBV - Obtain the basis vectors object associated to the nonlinear
     411             :    eigensolver object.
     412             : 
     413             :    Not Collective
     414             : 
     415             :    Input Parameters:
     416             : .  nep - eigensolver context obtained from NEPCreate()
     417             : 
     418             :    Output Parameter:
     419             : .  bv - basis vectors context
     420             : 
     421             :    Level: advanced
     422             : 
     423             : .seealso: NEPSetBV()
     424             : @*/
     425         125 : PetscErrorCode NEPGetBV(NEP nep,BV *bv)
     426             : {
     427         125 :   PetscErrorCode ierr;
     428             : 
     429         125 :   PetscFunctionBegin;
     430         125 :   PetscValidHeaderSpecific(nep,NEP_CLASSID,1);
     431         125 :   PetscValidPointer(bv,2);
     432         125 :   if (!nep->V) {
     433         124 :     ierr = BVCreate(PetscObjectComm((PetscObject)nep),&nep->V);CHKERRQ(ierr);
     434         124 :     ierr = PetscObjectIncrementTabLevel((PetscObject)nep->V,(PetscObject)nep,0);CHKERRQ(ierr);
     435         124 :     ierr = PetscLogObjectParent((PetscObject)nep,(PetscObject)nep->V);CHKERRQ(ierr);
     436         124 :     ierr = PetscObjectSetOptions((PetscObject)nep->V,((PetscObject)nep)->options);CHKERRQ(ierr);
     437             :   }
     438         125 :   *bv = nep->V;
     439         125 :   PetscFunctionReturn(0);
     440             : }
     441             : 
     442             : /*@
     443             :    NEPSetRG - Associates a region object to the nonlinear eigensolver.
     444             : 
     445             :    Collective on nep
     446             : 
     447             :    Input Parameters:
     448             : +  nep - eigensolver context obtained from NEPCreate()
     449             : -  rg  - the region object
     450             : 
     451             :    Note:
     452             :    Use NEPGetRG() to retrieve the region context (for example,
     453             :    to free it at the end of the computations).
     454             : 
     455             :    Level: advanced
     456             : 
     457             : .seealso: NEPGetRG()
     458             : @*/
     459           2 : PetscErrorCode NEPSetRG(NEP nep,RG rg)
     460             : {
     461           2 :   PetscErrorCode ierr;
     462             : 
     463           2 :   PetscFunctionBegin;
     464           2 :   PetscValidHeaderSpecific(nep,NEP_CLASSID,1);
     465           2 :   if (rg) {
     466           2 :     PetscValidHeaderSpecific(rg,RG_CLASSID,2);
     467           2 :     PetscCheckSameComm(nep,1,rg,2);
     468             :   }
     469           2 :   ierr = PetscObjectReference((PetscObject)rg);CHKERRQ(ierr);
     470           2 :   ierr = RGDestroy(&nep->rg);CHKERRQ(ierr);
     471           2 :   nep->rg = rg;
     472           2 :   ierr = PetscLogObjectParent((PetscObject)nep,(PetscObject)nep->rg);CHKERRQ(ierr);
     473           2 :   PetscFunctionReturn(0);
     474             : }
     475             : 
     476             : /*@
     477             :    NEPGetRG - Obtain the region object associated to the
     478             :    nonlinear eigensolver object.
     479             : 
     480             :    Not Collective
     481             : 
     482             :    Input Parameters:
     483             : .  nep - eigensolver context obtained from NEPCreate()
     484             : 
     485             :    Output Parameter:
     486             : .  rg - region context
     487             : 
     488             :    Level: advanced
     489             : 
     490             : .seealso: NEPSetRG()
     491             : @*/
     492         109 : PetscErrorCode NEPGetRG(NEP nep,RG *rg)
     493             : {
     494         109 :   PetscErrorCode ierr;
     495             : 
     496         109 :   PetscFunctionBegin;
     497         109 :   PetscValidHeaderSpecific(nep,NEP_CLASSID,1);
     498         109 :   PetscValidPointer(rg,2);
     499         109 :   if (!nep->rg) {
     500         108 :     ierr = RGCreate(PetscObjectComm((PetscObject)nep),&nep->rg);CHKERRQ(ierr);
     501         108 :     ierr = PetscObjectIncrementTabLevel((PetscObject)nep->rg,(PetscObject)nep,0);CHKERRQ(ierr);
     502         108 :     ierr = PetscLogObjectParent((PetscObject)nep,(PetscObject)nep->rg);CHKERRQ(ierr);
     503         108 :     ierr = PetscObjectSetOptions((PetscObject)nep->rg,((PetscObject)nep)->options);CHKERRQ(ierr);
     504             :   }
     505         109 :   *rg = nep->rg;
     506         109 :   PetscFunctionReturn(0);
     507             : }
     508             : 
     509             : /*@
     510             :    NEPSetDS - Associates a direct solver object to the nonlinear eigensolver.
     511             : 
     512             :    Collective on nep
     513             : 
     514             :    Input Parameters:
     515             : +  nep - eigensolver context obtained from NEPCreate()
     516             : -  ds  - the direct solver object
     517             : 
     518             :    Note:
     519             :    Use NEPGetDS() to retrieve the direct solver context (for example,
     520             :    to free it at the end of the computations).
     521             : 
     522             :    Level: advanced
     523             : 
     524             : .seealso: NEPGetDS()
     525             : @*/
     526           0 : PetscErrorCode NEPSetDS(NEP nep,DS ds)
     527             : {
     528           0 :   PetscErrorCode ierr;
     529             : 
     530           0 :   PetscFunctionBegin;
     531           0 :   PetscValidHeaderSpecific(nep,NEP_CLASSID,1);
     532           0 :   PetscValidHeaderSpecific(ds,DS_CLASSID,2);
     533           0 :   PetscCheckSameComm(nep,1,ds,2);
     534           0 :   ierr = PetscObjectReference((PetscObject)ds);CHKERRQ(ierr);
     535           0 :   ierr = DSDestroy(&nep->ds);CHKERRQ(ierr);
     536           0 :   nep->ds = ds;
     537           0 :   ierr = PetscLogObjectParent((PetscObject)nep,(PetscObject)nep->ds);CHKERRQ(ierr);
     538           0 :   PetscFunctionReturn(0);
     539             : }
     540             : 
     541             : /*@
     542             :    NEPGetDS - Obtain the direct solver object associated to the
     543             :    nonlinear eigensolver object.
     544             : 
     545             :    Not Collective
     546             : 
     547             :    Input Parameters:
     548             : .  nep - eigensolver context obtained from NEPCreate()
     549             : 
     550             :    Output Parameter:
     551             : .  ds - direct solver context
     552             : 
     553             :    Level: advanced
     554             : 
     555             : .seealso: NEPSetDS()
     556             : @*/
     557          87 : PetscErrorCode NEPGetDS(NEP nep,DS *ds)
     558             : {
     559          87 :   PetscErrorCode ierr;
     560             : 
     561          87 :   PetscFunctionBegin;
     562          87 :   PetscValidHeaderSpecific(nep,NEP_CLASSID,1);
     563          87 :   PetscValidPointer(ds,2);
     564          87 :   if (!nep->ds) {
     565          86 :     ierr = DSCreate(PetscObjectComm((PetscObject)nep),&nep->ds);CHKERRQ(ierr);
     566          86 :     ierr = PetscObjectIncrementTabLevel((PetscObject)nep->ds,(PetscObject)nep,0);CHKERRQ(ierr);
     567          86 :     ierr = PetscLogObjectParent((PetscObject)nep,(PetscObject)nep->ds);CHKERRQ(ierr);
     568          86 :     ierr = PetscObjectSetOptions((PetscObject)nep->ds,((PetscObject)nep)->options);CHKERRQ(ierr);
     569             :   }
     570          87 :   *ds = nep->ds;
     571          87 :   PetscFunctionReturn(0);
     572             : }
     573             : 
     574             : /*@
     575             :    NEPRefineGetKSP - Obtain the ksp object used by the eigensolver
     576             :    object in the refinement phase.
     577             : 
     578             :    Not Collective
     579             : 
     580             :    Input Parameters:
     581             : .  nep - eigensolver context obtained from NEPCreate()
     582             : 
     583             :    Output Parameter:
     584             : .  ksp - ksp context
     585             : 
     586             :    Level: advanced
     587             : 
     588             : .seealso: NEPSetRefine()
     589             : @*/
     590         114 : PetscErrorCode NEPRefineGetKSP(NEP nep,KSP *ksp)
     591             : {
     592         114 :   PetscErrorCode ierr;
     593             : 
     594         114 :   PetscFunctionBegin;
     595         114 :   PetscValidHeaderSpecific(nep,NEP_CLASSID,1);
     596         114 :   PetscValidPointer(ksp,2);
     597         114 :   if (!nep->refineksp) {
     598         110 :     if (nep->npart>1) {
     599             :       /* Split in subcomunicators */
     600           8 :       ierr = PetscSubcommCreate(PetscObjectComm((PetscObject)nep),&nep->refinesubc);CHKERRQ(ierr);
     601           8 :       ierr = PetscSubcommSetNumber(nep->refinesubc,nep->npart);CHKERRQ(ierr);CHKERRQ(ierr);
     602           8 :       ierr = PetscSubcommSetType(nep->refinesubc,PETSC_SUBCOMM_CONTIGUOUS);CHKERRQ(ierr);
     603           8 :       ierr = PetscLogObjectMemory((PetscObject)nep,sizeof(PetscSubcomm));CHKERRQ(ierr);
     604             :     }
     605         110 :     ierr = KSPCreate((nep->npart==1)?PetscObjectComm((PetscObject)nep):PetscSubcommChild(nep->refinesubc),&nep->refineksp);CHKERRQ(ierr);
     606         110 :     ierr = PetscObjectIncrementTabLevel((PetscObject)nep->refineksp,(PetscObject)nep,0);CHKERRQ(ierr);
     607         110 :     ierr = PetscLogObjectParent((PetscObject)nep,(PetscObject)nep->refineksp);CHKERRQ(ierr);
     608         110 :     ierr = PetscObjectSetOptions((PetscObject)nep->refineksp,((PetscObject)nep)->options);CHKERRQ(ierr);
     609         110 :     ierr = KSPSetOptionsPrefix(*ksp,((PetscObject)nep)->prefix);CHKERRQ(ierr);
     610         110 :     ierr = KSPAppendOptionsPrefix(*ksp,"nep_refine_");CHKERRQ(ierr);
     611         111 :     ierr = KSPSetTolerances(nep->refineksp,SlepcDefaultTol(nep->rtol),PETSC_DEFAULT,PETSC_DEFAULT,PETSC_DEFAULT);CHKERRQ(ierr);
     612             :   }
     613         114 :   *ksp = nep->refineksp;
     614         114 :   PetscFunctionReturn(0);
     615             : }
     616             : 
     617             : /*@
     618             :    NEPSetTarget - Sets the value of the target.
     619             : 
     620             :    Logically Collective on nep
     621             : 
     622             :    Input Parameters:
     623             : +  nep    - eigensolver context
     624             : -  target - the value of the target
     625             : 
     626             :    Options Database Key:
     627             : .  -nep_target <scalar> - the value of the target
     628             : 
     629             :    Notes:
     630             :    The target is a scalar value used to determine the portion of the spectrum
     631             :    of interest. It is used in combination with NEPSetWhichEigenpairs().
     632             : 
     633             :    In the case of complex scalars, a complex value can be provided in the
     634             :    command line with [+/-][realnumber][+/-]realnumberi with no spaces, e.g.
     635             :    -nep_target 1.0+2.0i
     636             : 
     637             :    Level: intermediate
     638             : 
     639             : .seealso: NEPGetTarget(), NEPSetWhichEigenpairs()
     640             : @*/
     641          87 : PetscErrorCode NEPSetTarget(NEP nep,PetscScalar target)
     642             : {
     643          87 :   PetscFunctionBegin;
     644          87 :   PetscValidHeaderSpecific(nep,NEP_CLASSID,1);
     645         174 :   PetscValidLogicalCollectiveScalar(nep,target,2);
     646          87 :   nep->target = target;
     647          87 :   PetscFunctionReturn(0);
     648             : }
     649             : 
     650             : /*@
     651             :    NEPGetTarget - Gets the value of the target.
     652             : 
     653             :    Not Collective
     654             : 
     655             :    Input Parameter:
     656             : .  nep - eigensolver context
     657             : 
     658             :    Output Parameter:
     659             : .  target - the value of the target
     660             : 
     661             :    Note:
     662             :    If the target was not set by the user, then zero is returned.
     663             : 
     664             :    Level: intermediate
     665             : 
     666             : .seealso: NEPSetTarget()
     667             : @*/
     668           1 : PetscErrorCode NEPGetTarget(NEP nep,PetscScalar* target)
     669             : {
     670           1 :   PetscFunctionBegin;
     671           1 :   PetscValidHeaderSpecific(nep,NEP_CLASSID,1);
     672           1 :   PetscValidScalarPointer(target,2);
     673           1 :   *target = nep->target;
     674           1 :   PetscFunctionReturn(0);
     675             : }
     676             : 
     677             : /*@C
     678             :    NEPSetFunction - Sets the function to compute the nonlinear Function T(lambda)
     679             :    as well as the location to store the matrix.
     680             : 
     681             :    Logically Collective on nep
     682             : 
     683             :    Input Parameters:
     684             : +  nep - the NEP context
     685             : .  A   - Function matrix
     686             : .  B   - preconditioner matrix (usually same as the Function)
     687             : .  fun - Function evaluation routine (if NULL then NEP retains any
     688             :          previously set value)
     689             : -  ctx - [optional] user-defined context for private data for the Function
     690             :          evaluation routine (may be NULL) (if NULL then NEP retains any
     691             :          previously set value)
     692             : 
     693             :    Calling Sequence of fun:
     694             : $   fun(NEP nep,PetscScalar lambda,Mat F,Mat P,void *ctx)
     695             : 
     696             : +  nep    - the NEP context
     697             : .  lambda - the scalar argument where T(.) must be evaluated
     698             : .  T      - matrix that will contain T(lambda)
     699             : .  P      - (optional) different matrix to build the preconditioner
     700             : -  ctx    - (optional) user-defined context, as set by NEPSetFunction()
     701             : 
     702             :    Level: beginner
     703             : 
     704             : .seealso: NEPGetFunction(), NEPSetJacobian()
     705             : @*/
     706          19 : PetscErrorCode NEPSetFunction(NEP nep,Mat A,Mat B,PetscErrorCode (*fun)(NEP,PetscScalar,Mat,Mat,void*),void *ctx)
     707             : {
     708          19 :   PetscErrorCode ierr;
     709             : 
     710          19 :   PetscFunctionBegin;
     711          19 :   PetscValidHeaderSpecific(nep,NEP_CLASSID,1);
     712          19 :   if (A) PetscValidHeaderSpecific(A,MAT_CLASSID,2);
     713          19 :   if (B) PetscValidHeaderSpecific(B,MAT_CLASSID,3);
     714          19 :   if (A) PetscCheckSameComm(nep,1,A,2);
     715          19 :   if (B) PetscCheckSameComm(nep,1,B,3);
     716             : 
     717          19 :   if (nep->state) { ierr = NEPReset(nep);CHKERRQ(ierr); }
     718          19 :   else if (nep->fui && nep->fui!=NEP_USER_INTERFACE_CALLBACK) { ierr = NEPReset_Problem(nep);CHKERRQ(ierr); }
     719             : 
     720          19 :   if (fun) nep->computefunction = fun;
     721          19 :   if (ctx) nep->functionctx     = ctx;
     722          19 :   if (A) {
     723          19 :     ierr = PetscObjectReference((PetscObject)A);CHKERRQ(ierr);
     724          19 :     ierr = MatDestroy(&nep->function);CHKERRQ(ierr);
     725          19 :     nep->function = A;
     726             :   }
     727          19 :   if (B) {
     728          19 :     ierr = PetscObjectReference((PetscObject)B);CHKERRQ(ierr);
     729          19 :     ierr = MatDestroy(&nep->function_pre);CHKERRQ(ierr);
     730          19 :     nep->function_pre = B;
     731             :   }
     732          19 :   nep->fui   = NEP_USER_INTERFACE_CALLBACK;
     733          19 :   nep->state = NEP_STATE_INITIAL;
     734          19 :   PetscFunctionReturn(0);
     735             : }
     736             : 
     737             : /*@C
     738             :    NEPGetFunction - Returns the Function matrix and optionally the user
     739             :    provided context for evaluating the Function.
     740             : 
     741             :    Not Collective, but Mat object will be parallel if NEP object is
     742             : 
     743             :    Input Parameter:
     744             : .  nep - the nonlinear eigensolver context
     745             : 
     746             :    Output Parameters:
     747             : +  A   - location to stash Function matrix (or NULL)
     748             : .  B   - location to stash preconditioner matrix (or NULL)
     749             : .  fun - location to put Function function (or NULL)
     750             : -  ctx - location to stash Function context (or NULL)
     751             : 
     752             :    Level: advanced
     753             : 
     754             : .seealso: NEPSetFunction()
     755             : @*/
     756          38 : PetscErrorCode NEPGetFunction(NEP nep,Mat *A,Mat *B,PetscErrorCode (**fun)(NEP,PetscScalar,Mat,Mat,void*),void **ctx)
     757             : {
     758          38 :   PetscFunctionBegin;
     759          38 :   PetscValidHeaderSpecific(nep,NEP_CLASSID,1);
     760          38 :   NEPCheckCallback(nep,1);
     761          38 :   if (A)   *A   = nep->function;
     762          38 :   if (B)   *B   = nep->function_pre;
     763          38 :   if (fun) *fun = nep->computefunction;
     764          38 :   if (ctx) *ctx = nep->functionctx;
     765          38 :   PetscFunctionReturn(0);
     766             : }
     767             : 
     768             : /*@C
     769             :    NEPSetJacobian - Sets the function to compute Jacobian T'(lambda) as well
     770             :    as the location to store the matrix.
     771             : 
     772             :    Logically Collective on nep
     773             : 
     774             :    Input Parameters:
     775             : +  nep - the NEP context
     776             : .  A   - Jacobian matrix
     777             : .  jac - Jacobian evaluation routine (if NULL then NEP retains any
     778             :          previously set value)
     779             : -  ctx - [optional] user-defined context for private data for the Jacobian
     780             :          evaluation routine (may be NULL) (if NULL then NEP retains any
     781             :          previously set value)
     782             : 
     783             :    Calling Sequence of jac:
     784             : $   jac(NEP nep,PetscScalar lambda,Mat J,void *ctx)
     785             : 
     786             : +  nep    - the NEP context
     787             : .  lambda - the scalar argument where T'(.) must be evaluated
     788             : .  J      - matrix that will contain T'(lambda)
     789             : -  ctx    - (optional) user-defined context, as set by NEPSetJacobian()
     790             : 
     791             :    Level: beginner
     792             : 
     793             : .seealso: NEPSetFunction(), NEPGetJacobian()
     794             : @*/
     795          18 : PetscErrorCode NEPSetJacobian(NEP nep,Mat A,PetscErrorCode (*jac)(NEP,PetscScalar,Mat,void*),void *ctx)
     796             : {
     797          18 :   PetscErrorCode ierr;
     798             : 
     799          18 :   PetscFunctionBegin;
     800          18 :   PetscValidHeaderSpecific(nep,NEP_CLASSID,1);
     801          18 :   if (A) PetscValidHeaderSpecific(A,MAT_CLASSID,2);
     802          18 :   if (A) PetscCheckSameComm(nep,1,A,2);
     803             : 
     804          18 :   if (nep->state) { ierr = NEPReset(nep);CHKERRQ(ierr); }
     805          18 :   else if (nep->fui && nep->fui!=NEP_USER_INTERFACE_CALLBACK) { ierr = NEPReset_Problem(nep);CHKERRQ(ierr); }
     806             : 
     807          18 :   if (jac) nep->computejacobian = jac;
     808          18 :   if (ctx) nep->jacobianctx     = ctx;
     809          18 :   if (A) {
     810          18 :     ierr = PetscObjectReference((PetscObject)A);CHKERRQ(ierr);
     811          18 :     ierr = MatDestroy(&nep->jacobian);CHKERRQ(ierr);
     812          18 :     nep->jacobian = A;
     813             :   }
     814          18 :   nep->fui   = NEP_USER_INTERFACE_CALLBACK;
     815          18 :   nep->state = NEP_STATE_INITIAL;
     816          18 :   PetscFunctionReturn(0);
     817             : }
     818             : 
     819             : /*@C
     820             :    NEPGetJacobian - Returns the Jacobian matrix and optionally the user
     821             :    provided routine and context for evaluating the Jacobian.
     822             : 
     823             :    Not Collective, but Mat object will be parallel if NEP object is
     824             : 
     825             :    Input Parameter:
     826             : .  nep - the nonlinear eigensolver context
     827             : 
     828             :    Output Parameters:
     829             : +  A   - location to stash Jacobian matrix (or NULL)
     830             : .  jac - location to put Jacobian function (or NULL)
     831             : -  ctx - location to stash Jacobian context (or NULL)
     832             : 
     833             :    Level: advanced
     834             : 
     835             : .seealso: NEPSetJacobian()
     836             : @*/
     837           0 : PetscErrorCode NEPGetJacobian(NEP nep,Mat *A,PetscErrorCode (**jac)(NEP,PetscScalar,Mat,void*),void **ctx)
     838             : {
     839           0 :   PetscFunctionBegin;
     840           0 :   PetscValidHeaderSpecific(nep,NEP_CLASSID,1);
     841           0 :   NEPCheckCallback(nep,1);
     842           0 :   if (A)   *A   = nep->jacobian;
     843           0 :   if (jac) *jac = nep->computejacobian;
     844           0 :   if (ctx) *ctx = nep->jacobianctx;
     845           0 :   PetscFunctionReturn(0);
     846             : }
     847             : 
     848             : /*@
     849             :    NEPSetSplitOperator - Sets the operator of the nonlinear eigenvalue problem
     850             :    in split form.
     851             : 
     852             :    Collective on nep
     853             : 
     854             :    Input Parameters:
     855             : +  nep - the nonlinear eigensolver context
     856             : .  n   - number of terms in the split form
     857             : .  A   - array of matrices
     858             : .  f   - array of functions
     859             : -  str - structure flag for matrices
     860             : 
     861             :    Notes:
     862             :    The nonlinear operator is written as T(lambda) = sum_i A_i*f_i(lambda),
     863             :    for i=1,...,n. The derivative T'(lambda) can be obtained using the
     864             :    derivatives of f_i.
     865             : 
     866             :    The structure flag provides information about A_i's nonzero pattern
     867             :    (see MatStructure enum). If all matrices have the same pattern, then
     868             :    use SAME_NONZERO_PATTERN. If the patterns are different but contained
     869             :    in the pattern of the first one, then use SUBSET_NONZERO_PATTERN. If
     870             :    patterns are known to be different, use DIFFERENT_NONZERO_PATTERN.
     871             :    If set to UNKNOWN_NONZERO_PATTERN, the patterns will be compared to
     872             :    determine if they are equal.
     873             : 
     874             :    This function must be called before NEPSetUp(). If it is called again
     875             :    after NEPSetUp() then the NEP object is reset.
     876             : 
     877             :    Level: beginner
     878             : 
     879             : .seealso: NEPGetSplitOperatorTerm(), NEPGetSplitOperatorInfo()
     880             :  @*/
     881         105 : PetscErrorCode NEPSetSplitOperator(NEP nep,PetscInt nt,Mat A[],FN f[],MatStructure str)
     882             : {
     883         105 :   PetscInt       i,n=0,m,m0=0,mloc,nloc,mloc0=0;
     884         105 :   PetscErrorCode ierr;
     885             : 
     886         105 :   PetscFunctionBegin;
     887         105 :   PetscValidHeaderSpecific(nep,NEP_CLASSID,1);
     888         210 :   PetscValidLogicalCollectiveInt(nep,nt,2);
     889         105 :   if (nt <= 0) SETERRQ1(PetscObjectComm((PetscObject)nep),PETSC_ERR_ARG_OUTOFRANGE,"Must have one or more terms, you have %D",nt);
     890         105 :   PetscValidPointer(A,3);
     891         105 :   PetscValidPointer(f,4);
     892             : 
     893         409 :   for (i=0;i<nt;i++) {
     894         304 :     PetscValidHeaderSpecific(A[i],MAT_CLASSID,3);
     895         304 :     PetscCheckSameComm(nep,1,A[i],3);
     896         304 :     PetscValidHeaderSpecific(f[i],FN_CLASSID,4);
     897         304 :     PetscCheckSameComm(nep,1,f[i],4);
     898         304 :     ierr = MatGetSize(A[i],&m,&n);CHKERRQ(ierr);
     899         304 :     ierr = MatGetLocalSize(A[i],&mloc,&nloc);CHKERRQ(ierr);
     900         304 :     if (m!=n) SETERRQ3(PetscObjectComm((PetscObject)nep),PETSC_ERR_ARG_WRONG,"A[%D] is a non-square matrix (%D rows, %D cols)",i,m,n);
     901         304 :     if (mloc!=nloc) SETERRQ3(PetscObjectComm((PetscObject)nep),PETSC_ERR_ARG_WRONG,"A[%D] does not have equal row and column local sizes (%D, %D)",i,mloc,nloc);
     902         304 :     if (!i) { m0 = m; mloc0 = mloc; }
     903         304 :     if (m!=m0) SETERRQ3(PetscObjectComm((PetscObject)nep),PETSC_ERR_ARG_INCOMP,"Dimensions of A[%D] do not match with previous matrices (%D, %D)",i,m,m0);
     904         304 :     if (mloc!=mloc0) SETERRQ3(PetscObjectComm((PetscObject)nep),PETSC_ERR_ARG_INCOMP,"Local dimensions of A[%D] do not match with previous matrices (%D, %D)",i,mloc,mloc0);
     905         304 :     ierr = PetscObjectReference((PetscObject)A[i]);CHKERRQ(ierr);
     906         304 :     ierr = PetscObjectReference((PetscObject)f[i]);CHKERRQ(ierr);
     907             :   }
     908             : 
     909         105 :   if (nep->state && (n!=nep->n || nloc!=nep->nloc)) { ierr = NEPReset(nep);CHKERRQ(ierr); }
     910          91 :   else { ierr = NEPReset_Problem(nep);CHKERRQ(ierr); }
     911             : 
     912             :   /* allocate space and copy matrices and functions */
     913         105 :   ierr = PetscMalloc1(nt,&nep->A);CHKERRQ(ierr);
     914         105 :   ierr = PetscLogObjectMemory((PetscObject)nep,nt*sizeof(Mat));CHKERRQ(ierr);
     915         409 :   for (i=0;i<nt;i++) nep->A[i] = A[i];
     916         105 :   ierr = PetscMalloc1(nt,&nep->f);CHKERRQ(ierr);
     917         105 :   ierr = PetscLogObjectMemory((PetscObject)nep,nt*sizeof(FN));CHKERRQ(ierr);
     918         409 :   for (i=0;i<nt;i++) nep->f[i] = f[i];
     919         105 :   ierr = PetscCalloc1(nt,&nep->nrma);CHKERRQ(ierr);
     920         105 :   ierr = PetscLogObjectMemory((PetscObject)nep,nt*sizeof(PetscReal));CHKERRQ(ierr);
     921         105 :   nep->nt    = nt;
     922         105 :   nep->mstr  = str;
     923         105 :   nep->fui   = NEP_USER_INTERFACE_SPLIT;
     924         105 :   nep->state = NEP_STATE_INITIAL;
     925         105 :   PetscFunctionReturn(0);
     926             : }
     927             : 
     928             : /*@
     929             :    NEPGetSplitOperatorTerm - Gets the matrices and functions associated with
     930             :    the nonlinear operator in split form.
     931             : 
     932             :    Not collective, though parallel Mats and FNs are returned if the NEP is parallel
     933             : 
     934             :    Input Parameters:
     935             : +  nep - the nonlinear eigensolver context
     936             : -  k   - the index of the requested term (starting in 0)
     937             : 
     938             :    Output Parameters:
     939             : +  A - the matrix of the requested term
     940             : -  f - the function of the requested term
     941             : 
     942             :    Level: intermediate
     943             : 
     944             : .seealso: NEPSetSplitOperator(), NEPGetSplitOperatorInfo()
     945             : @*/
     946          54 : PetscErrorCode NEPGetSplitOperatorTerm(NEP nep,PetscInt k,Mat *A,FN *f)
     947             : {
     948          54 :   PetscFunctionBegin;
     949          54 :   PetscValidHeaderSpecific(nep,NEP_CLASSID,1);
     950          54 :   NEPCheckSplit(nep,1);
     951          54 :   if (k<0 || k>=nep->nt) SETERRQ1(PetscObjectComm((PetscObject)nep),PETSC_ERR_ARG_OUTOFRANGE,"k must be between 0 and %D",nep->nt-1);
     952          54 :   if (A) *A = nep->A[k];
     953          54 :   if (f) *f = nep->f[k];
     954          54 :   PetscFunctionReturn(0);
     955             : }
     956             : 
     957             : /*@
     958             :    NEPGetSplitOperatorInfo - Returns the number of terms of the split form of
     959             :    the nonlinear operator, as well as the structure flag for matrices.
     960             : 
     961             :    Not collective
     962             : 
     963             :    Input Parameter:
     964             : .  nep - the nonlinear eigensolver context
     965             : 
     966             :    Output Parameters:
     967             : +  n   - the number of terms passed in NEPSetSplitOperator()
     968             : -  str - the matrix structure flag passed in NEPSetSplitOperator()
     969             : 
     970             :    Level: intermediate
     971             : 
     972             : .seealso: NEPSetSplitOperator(), NEPGetSplitOperatorTerm()
     973             : @*/
     974           9 : PetscErrorCode NEPGetSplitOperatorInfo(NEP nep,PetscInt *n,MatStructure *str)
     975             : {
     976           9 :   PetscFunctionBegin;
     977           9 :   PetscValidHeaderSpecific(nep,NEP_CLASSID,1);
     978           9 :   NEPCheckSplit(nep,1);
     979           9 :   if (n)   *n = nep->nt;
     980           9 :   if (str) *str = nep->mstr;
     981           9 :   PetscFunctionReturn(0);
     982             : }
     983             : 

Generated by: LCOV version 1.14