LCOV - code coverage report
Current view: top level - pep/interface - pepbasic.c (source / functions) Hit Total Coverage
Test: SLEPc Lines: 256 274 93.4 %
Date: 2024-11-21 00:40:22 Functions: 18 20 90.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       3             :    SLEPc - Scalable Library for Eigenvalue Problem Computations
       4             :    Copyright (c) 2002-, 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 PEP routines
      12             : */
      13             : 
      14             : #include <slepc/private/pepimpl.h>      /*I "slepcpep.h" I*/
      15             : 
      16             : /* Logging support */
      17             : PetscClassId      PEP_CLASSID = 0;
      18             : PetscLogEvent     PEP_SetUp = 0,PEP_Solve = 0,PEP_Refine = 0,PEP_CISS_SVD = 0;
      19             : 
      20             : /* List of registered PEP routines */
      21             : PetscFunctionList PEPList = NULL;
      22             : PetscBool         PEPRegisterAllCalled = PETSC_FALSE;
      23             : 
      24             : /* List of registered PEP monitors */
      25             : PetscFunctionList PEPMonitorList              = NULL;
      26             : PetscFunctionList PEPMonitorCreateList        = NULL;
      27             : PetscFunctionList PEPMonitorDestroyList       = NULL;
      28             : PetscBool         PEPMonitorRegisterAllCalled = PETSC_FALSE;
      29             : 
      30             : /*@
      31             :    PEPCreate - Creates the default PEP context.
      32             : 
      33             :    Collective
      34             : 
      35             :    Input Parameter:
      36             : .  comm - MPI communicator
      37             : 
      38             :    Output Parameter:
      39             : .  outpep - location to put the PEP context
      40             : 
      41             :    Note:
      42             :    The default PEP type is PEPTOAR
      43             : 
      44             :    Level: beginner
      45             : 
      46             : .seealso: PEPSetUp(), PEPSolve(), PEPDestroy(), PEP
      47             : @*/
      48         182 : PetscErrorCode PEPCreate(MPI_Comm comm,PEP *outpep)
      49             : {
      50         182 :   PEP            pep;
      51             : 
      52         182 :   PetscFunctionBegin;
      53         182 :   PetscAssertPointer(outpep,2);
      54         182 :   PetscCall(PEPInitializePackage());
      55         182 :   PetscCall(SlepcHeaderCreate(pep,PEP_CLASSID,"PEP","Polynomial Eigenvalue Problem","PEP",comm,PEPDestroy,PEPView));
      56             : 
      57         182 :   pep->max_it          = PETSC_DETERMINE;
      58         182 :   pep->nev             = 1;
      59         182 :   pep->ncv             = PETSC_DETERMINE;
      60         182 :   pep->mpd             = PETSC_DETERMINE;
      61         182 :   pep->nini            = 0;
      62         182 :   pep->target          = 0.0;
      63         182 :   pep->tol             = PETSC_DETERMINE;
      64         182 :   pep->conv            = PEP_CONV_REL;
      65         182 :   pep->stop            = PEP_STOP_BASIC;
      66         182 :   pep->which           = (PEPWhich)0;
      67         182 :   pep->basis           = PEP_BASIS_MONOMIAL;
      68         182 :   pep->problem_type    = (PEPProblemType)0;
      69         182 :   pep->scale           = PEP_SCALE_NONE;
      70         182 :   pep->sfactor         = 1.0;
      71         182 :   pep->dsfactor        = 1.0;
      72         182 :   pep->sits            = 5;
      73         182 :   pep->slambda         = 1.0;
      74         182 :   pep->refine          = PEP_REFINE_NONE;
      75         182 :   pep->npart           = 1;
      76         182 :   pep->rtol            = PETSC_DETERMINE;
      77         182 :   pep->rits            = PETSC_DETERMINE;
      78         182 :   pep->scheme          = (PEPRefineScheme)0;
      79         182 :   pep->extract         = (PEPExtract)0;
      80         182 :   pep->trackall        = PETSC_FALSE;
      81             : 
      82         182 :   pep->converged       = PEPConvergedRelative;
      83         182 :   pep->convergeduser   = NULL;
      84         182 :   pep->convergeddestroy= NULL;
      85         182 :   pep->stopping        = PEPStoppingBasic;
      86         182 :   pep->stoppinguser    = NULL;
      87         182 :   pep->stoppingdestroy = NULL;
      88         182 :   pep->convergedctx    = NULL;
      89         182 :   pep->stoppingctx     = NULL;
      90         182 :   pep->numbermonitors  = 0;
      91             : 
      92         182 :   pep->st              = NULL;
      93         182 :   pep->ds              = NULL;
      94         182 :   pep->V               = NULL;
      95         182 :   pep->rg              = NULL;
      96         182 :   pep->A               = NULL;
      97         182 :   pep->nmat            = 0;
      98         182 :   pep->Dl              = NULL;
      99         182 :   pep->Dr              = NULL;
     100         182 :   pep->IS              = NULL;
     101         182 :   pep->eigr            = NULL;
     102         182 :   pep->eigi            = NULL;
     103         182 :   pep->errest          = NULL;
     104         182 :   pep->perm            = NULL;
     105         182 :   pep->pbc             = NULL;
     106         182 :   pep->solvematcoeffs  = NULL;
     107         182 :   pep->nwork           = 0;
     108         182 :   pep->work            = NULL;
     109         182 :   pep->refineksp       = NULL;
     110         182 :   pep->refinesubc      = NULL;
     111         182 :   pep->data            = NULL;
     112             : 
     113         182 :   pep->state           = PEP_STATE_INITIAL;
     114         182 :   pep->nconv           = 0;
     115         182 :   pep->its             = 0;
     116         182 :   pep->n               = 0;
     117         182 :   pep->nloc            = 0;
     118         182 :   pep->nrma            = NULL;
     119         182 :   pep->sfactor_set     = PETSC_FALSE;
     120         182 :   pep->lineariz        = PETSC_FALSE;
     121         182 :   pep->reason          = PEP_CONVERGED_ITERATING;
     122             : 
     123         182 :   PetscCall(PetscNew(&pep->sc));
     124         182 :   *outpep = pep;
     125         182 :   PetscFunctionReturn(PETSC_SUCCESS);
     126             : }
     127             : 
     128             : /*@
     129             :    PEPSetType - Selects the particular solver to be used in the PEP object.
     130             : 
     131             :    Logically Collective
     132             : 
     133             :    Input Parameters:
     134             : +  pep      - the polynomial eigensolver context
     135             : -  type     - a known method
     136             : 
     137             :    Options Database Key:
     138             : .  -pep_type <method> - Sets the method; use -help for a list
     139             :     of available methods
     140             : 
     141             :    Notes:
     142             :    See "slepc/include/slepcpep.h" for available methods. The default
     143             :    is PEPTOAR.
     144             : 
     145             :    Normally, it is best to use the PEPSetFromOptions() command and
     146             :    then set the PEP type from the options database rather than by using
     147             :    this routine.  Using the options database provides the user with
     148             :    maximum flexibility in evaluating the different available methods.
     149             :    The PEPSetType() routine is provided for those situations where it
     150             :    is necessary to set the iterative solver independently of the command
     151             :    line or options database.
     152             : 
     153             :    Level: intermediate
     154             : 
     155             : .seealso: PEPType
     156             : @*/
     157         182 : PetscErrorCode PEPSetType(PEP pep,PEPType type)
     158             : {
     159         182 :   PetscErrorCode (*r)(PEP);
     160         182 :   PetscBool      match;
     161             : 
     162         182 :   PetscFunctionBegin;
     163         182 :   PetscValidHeaderSpecific(pep,PEP_CLASSID,1);
     164         182 :   PetscAssertPointer(type,2);
     165             : 
     166         182 :   PetscCall(PetscObjectTypeCompare((PetscObject)pep,type,&match));
     167         182 :   if (match) PetscFunctionReturn(PETSC_SUCCESS);
     168             : 
     169         182 :   PetscCall(PetscFunctionListFind(PEPList,type,&r));
     170         182 :   PetscCheck(r,PetscObjectComm((PetscObject)pep),PETSC_ERR_ARG_UNKNOWN_TYPE,"Unknown PEP type given: %s",type);
     171             : 
     172         182 :   PetscTryTypeMethod(pep,destroy);
     173         182 :   PetscCall(PetscMemzero(pep->ops,sizeof(struct _PEPOps)));
     174             : 
     175         182 :   pep->state = PEP_STATE_INITIAL;
     176         182 :   PetscCall(PetscObjectChangeTypeName((PetscObject)pep,type));
     177         182 :   PetscCall((*r)(pep));
     178         182 :   PetscFunctionReturn(PETSC_SUCCESS);
     179             : }
     180             : 
     181             : /*@
     182             :    PEPGetType - Gets the PEP type as a string from the PEP object.
     183             : 
     184             :    Not Collective
     185             : 
     186             :    Input Parameter:
     187             : .  pep - the eigensolver context
     188             : 
     189             :    Output Parameter:
     190             : .  type - name of PEP method
     191             : 
     192             :    Level: intermediate
     193             : 
     194             : .seealso: PEPSetType()
     195             : @*/
     196           6 : PetscErrorCode PEPGetType(PEP pep,PEPType *type)
     197             : {
     198           6 :   PetscFunctionBegin;
     199           6 :   PetscValidHeaderSpecific(pep,PEP_CLASSID,1);
     200           6 :   PetscAssertPointer(type,2);
     201           6 :   *type = ((PetscObject)pep)->type_name;
     202           6 :   PetscFunctionReturn(PETSC_SUCCESS);
     203             : }
     204             : 
     205             : /*@C
     206             :    PEPRegister - Adds a method to the polynomial eigenproblem solver package.
     207             : 
     208             :    Not Collective
     209             : 
     210             :    Input Parameters:
     211             : +  name - name of a new user-defined solver
     212             : -  function - routine to create the solver context
     213             : 
     214             :    Notes:
     215             :    PEPRegister() may be called multiple times to add several user-defined solvers.
     216             : 
     217             :    Example Usage:
     218             : .vb
     219             :     PEPRegister("my_solver",MySolverCreate);
     220             : .ve
     221             : 
     222             :    Then, your solver can be chosen with the procedural interface via
     223             : $     PEPSetType(pep,"my_solver")
     224             :    or at runtime via the option
     225             : $     -pep_type my_solver
     226             : 
     227             :    Level: advanced
     228             : 
     229             : .seealso: PEPRegisterAll()
     230             : @*/
     231        1074 : PetscErrorCode PEPRegister(const char *name,PetscErrorCode (*function)(PEP))
     232             : {
     233        1074 :   PetscFunctionBegin;
     234        1074 :   PetscCall(PEPInitializePackage());
     235        1074 :   PetscCall(PetscFunctionListAdd(&PEPList,name,function));
     236        1074 :   PetscFunctionReturn(PETSC_SUCCESS);
     237             : }
     238             : 
     239             : /*@C
     240             :    PEPMonitorRegister - Adds PEP monitor routine.
     241             : 
     242             :    Not Collective
     243             : 
     244             :    Input Parameters:
     245             : +  name    - name of a new monitor routine
     246             : .  vtype   - a PetscViewerType for the output
     247             : .  format  - a PetscViewerFormat for the output
     248             : .  monitor - monitor routine
     249             : .  create  - creation routine, or NULL
     250             : -  destroy - destruction routine, or NULL
     251             : 
     252             :    Notes:
     253             :    PEPMonitorRegister() may be called multiple times to add several user-defined monitors.
     254             : 
     255             :    Example Usage:
     256             : .vb
     257             :    PEPMonitorRegister("my_monitor",PETSCVIEWERASCII,PETSC_VIEWER_ASCII_INFO_DETAIL,MyMonitor,NULL,NULL);
     258             : .ve
     259             : 
     260             :    Then, your monitor can be chosen with the procedural interface via
     261             : $      PEPMonitorSetFromOptions(pep,"-pep_monitor_my_monitor","my_monitor",NULL)
     262             :    or at runtime via the option
     263             : $      -pep_monitor_my_monitor
     264             : 
     265             :    Level: advanced
     266             : 
     267             : .seealso: PEPMonitorRegisterAll()
     268             : @*/
     269        1074 : PetscErrorCode PEPMonitorRegister(const char name[],PetscViewerType vtype,PetscViewerFormat format,PetscErrorCode (*monitor)(PEP,PetscInt,PetscInt,PetscScalar*,PetscScalar*,PetscReal*,PetscInt,PetscViewerAndFormat*),PetscErrorCode (*create)(PetscViewer,PetscViewerFormat,void*,PetscViewerAndFormat**),PetscErrorCode (*destroy)(PetscViewerAndFormat**))
     270             : {
     271        1074 :   char           key[PETSC_MAX_PATH_LEN];
     272             : 
     273        1074 :   PetscFunctionBegin;
     274        1074 :   PetscCall(PEPInitializePackage());
     275        1074 :   PetscCall(SlepcMonitorMakeKey_Internal(name,vtype,format,key));
     276        1074 :   PetscCall(PetscFunctionListAdd(&PEPMonitorList,key,monitor));
     277        1074 :   if (create)  PetscCall(PetscFunctionListAdd(&PEPMonitorCreateList,key,create));
     278        1074 :   if (destroy) PetscCall(PetscFunctionListAdd(&PEPMonitorDestroyList,key,destroy));
     279        1074 :   PetscFunctionReturn(PETSC_SUCCESS);
     280             : }
     281             : 
     282             : /*@
     283             :    PEPReset - Resets the PEP context to the initial state (prior to setup)
     284             :    and destroys any allocated Vecs and Mats.
     285             : 
     286             :    Collective
     287             : 
     288             :    Input Parameter:
     289             : .  pep - eigensolver context obtained from PEPCreate()
     290             : 
     291             :    Level: advanced
     292             : 
     293             : .seealso: PEPDestroy()
     294             : @*/
     295         209 : PetscErrorCode PEPReset(PEP pep)
     296             : {
     297         209 :   PetscFunctionBegin;
     298         209 :   if (pep) PetscValidHeaderSpecific(pep,PEP_CLASSID,1);
     299         209 :   if (!pep) PetscFunctionReturn(PETSC_SUCCESS);
     300         209 :   PetscTryTypeMethod(pep,reset);
     301         209 :   if (pep->st) PetscCall(STReset(pep->st));
     302         209 :   if (pep->refineksp) PetscCall(KSPReset(pep->refineksp));
     303         209 :   if (pep->nmat) {
     304         189 :     PetscCall(MatDestroyMatrices(pep->nmat,&pep->A));
     305         189 :     PetscCall(PetscFree2(pep->pbc,pep->nrma));
     306         189 :     PetscCall(PetscFree(pep->solvematcoeffs));
     307         189 :     pep->nmat = 0;
     308             :   }
     309         209 :   PetscCall(VecDestroy(&pep->Dl));
     310         209 :   PetscCall(VecDestroy(&pep->Dr));
     311         209 :   PetscCall(BVDestroy(&pep->V));
     312         209 :   PetscCall(VecDestroyVecs(pep->nwork,&pep->work));
     313         209 :   pep->nwork = 0;
     314         209 :   pep->state = PEP_STATE_INITIAL;
     315         209 :   PetscFunctionReturn(PETSC_SUCCESS);
     316             : }
     317             : 
     318             : /*@
     319             :    PEPDestroy - Destroys the PEP context.
     320             : 
     321             :    Collective
     322             : 
     323             :    Input Parameter:
     324             : .  pep - eigensolver context obtained from PEPCreate()
     325             : 
     326             :    Level: beginner
     327             : 
     328             : .seealso: PEPCreate(), PEPSetUp(), PEPSolve()
     329             : @*/
     330         184 : PetscErrorCode PEPDestroy(PEP *pep)
     331             : {
     332         184 :   PetscFunctionBegin;
     333         184 :   if (!*pep) PetscFunctionReturn(PETSC_SUCCESS);
     334         183 :   PetscValidHeaderSpecific(*pep,PEP_CLASSID,1);
     335         183 :   if (--((PetscObject)*pep)->refct > 0) { *pep = NULL; PetscFunctionReturn(PETSC_SUCCESS); }
     336         182 :   PetscCall(PEPReset(*pep));
     337         182 :   PetscTryTypeMethod(*pep,destroy);
     338         182 :   if ((*pep)->eigr) PetscCall(PetscFree4((*pep)->eigr,(*pep)->eigi,(*pep)->errest,(*pep)->perm));
     339         182 :   PetscCall(STDestroy(&(*pep)->st));
     340         182 :   PetscCall(RGDestroy(&(*pep)->rg));
     341         182 :   PetscCall(DSDestroy(&(*pep)->ds));
     342         182 :   PetscCall(KSPDestroy(&(*pep)->refineksp));
     343         182 :   PetscCall(PetscSubcommDestroy(&(*pep)->refinesubc));
     344         182 :   PetscCall(PetscFree((*pep)->sc));
     345             :   /* just in case the initial vectors have not been used */
     346         182 :   PetscCall(SlepcBasisDestroy_Private(&(*pep)->nini,&(*pep)->IS));
     347         182 :   if ((*pep)->convergeddestroy) PetscCall((*(*pep)->convergeddestroy)(&(*pep)->convergedctx));
     348         182 :   if ((*pep)->stoppingdestroy) PetscCall((*(*pep)->stoppingdestroy)(&(*pep)->stoppingctx));
     349         182 :   PetscCall(PEPMonitorCancel(*pep));
     350         182 :   PetscCall(PetscHeaderDestroy(pep));
     351         182 :   PetscFunctionReturn(PETSC_SUCCESS);
     352             : }
     353             : 
     354             : /*@
     355             :    PEPSetBV - Associates a basis vectors object to the polynomial eigensolver.
     356             : 
     357             :    Collective
     358             : 
     359             :    Input Parameters:
     360             : +  pep - eigensolver context obtained from PEPCreate()
     361             : -  bv  - the basis vectors object
     362             : 
     363             :    Note:
     364             :    Use PEPGetBV() to retrieve the basis vectors context (for example,
     365             :    to free it at the end of the computations).
     366             : 
     367             :    Level: advanced
     368             : 
     369             : .seealso: PEPGetBV()
     370             : @*/
     371           0 : PetscErrorCode PEPSetBV(PEP pep,BV bv)
     372             : {
     373           0 :   PetscFunctionBegin;
     374           0 :   PetscValidHeaderSpecific(pep,PEP_CLASSID,1);
     375           0 :   PetscValidHeaderSpecific(bv,BV_CLASSID,2);
     376           0 :   PetscCheckSameComm(pep,1,bv,2);
     377           0 :   PetscCall(PetscObjectReference((PetscObject)bv));
     378           0 :   PetscCall(BVDestroy(&pep->V));
     379           0 :   pep->V = bv;
     380           0 :   PetscFunctionReturn(PETSC_SUCCESS);
     381             : }
     382             : 
     383             : /*@
     384             :    PEPGetBV - Obtain the basis vectors object associated to the polynomial
     385             :    eigensolver object.
     386             : 
     387             :    Not Collective
     388             : 
     389             :    Input Parameters:
     390             : .  pep - eigensolver context obtained from PEPCreate()
     391             : 
     392             :    Output Parameter:
     393             : .  bv - basis vectors context
     394             : 
     395             :    Level: advanced
     396             : 
     397             : .seealso: PEPSetBV()
     398             : @*/
     399         191 : PetscErrorCode PEPGetBV(PEP pep,BV *bv)
     400             : {
     401         191 :   PetscFunctionBegin;
     402         191 :   PetscValidHeaderSpecific(pep,PEP_CLASSID,1);
     403         191 :   PetscAssertPointer(bv,2);
     404         191 :   if (!pep->V) {
     405         189 :     PetscCall(BVCreate(PetscObjectComm((PetscObject)pep),&pep->V));
     406         189 :     PetscCall(PetscObjectIncrementTabLevel((PetscObject)pep->V,(PetscObject)pep,0));
     407         189 :     PetscCall(PetscObjectSetOptions((PetscObject)pep->V,((PetscObject)pep)->options));
     408             :   }
     409         191 :   *bv = pep->V;
     410         191 :   PetscFunctionReturn(PETSC_SUCCESS);
     411             : }
     412             : 
     413             : /*@
     414             :    PEPSetRG - Associates a region object to the polynomial eigensolver.
     415             : 
     416             :    Collective
     417             : 
     418             :    Input Parameters:
     419             : +  pep - eigensolver context obtained from PEPCreate()
     420             : -  rg  - the region object
     421             : 
     422             :    Note:
     423             :    Use PEPGetRG() to retrieve the region context (for example,
     424             :    to free it at the end of the computations).
     425             : 
     426             :    Level: advanced
     427             : 
     428             : .seealso: PEPGetRG()
     429             : @*/
     430           3 : PetscErrorCode PEPSetRG(PEP pep,RG rg)
     431             : {
     432           3 :   PetscFunctionBegin;
     433           3 :   PetscValidHeaderSpecific(pep,PEP_CLASSID,1);
     434           3 :   if (rg) {
     435           3 :     PetscValidHeaderSpecific(rg,RG_CLASSID,2);
     436           3 :     PetscCheckSameComm(pep,1,rg,2);
     437             :   }
     438           3 :   PetscCall(PetscObjectReference((PetscObject)rg));
     439           3 :   PetscCall(RGDestroy(&pep->rg));
     440           3 :   pep->rg = rg;
     441           3 :   PetscFunctionReturn(PETSC_SUCCESS);
     442             : }
     443             : 
     444             : /*@
     445             :    PEPGetRG - Obtain the region object associated to the
     446             :    polynomial eigensolver object.
     447             : 
     448             :    Not Collective
     449             : 
     450             :    Input Parameters:
     451             : .  pep - eigensolver context obtained from PEPCreate()
     452             : 
     453             :    Output Parameter:
     454             : .  rg - region context
     455             : 
     456             :    Level: advanced
     457             : 
     458             : .seealso: PEPSetRG()
     459             : @*/
     460         206 : PetscErrorCode PEPGetRG(PEP pep,RG *rg)
     461             : {
     462         206 :   PetscFunctionBegin;
     463         206 :   PetscValidHeaderSpecific(pep,PEP_CLASSID,1);
     464         206 :   PetscAssertPointer(rg,2);
     465         206 :   if (!pep->rg) {
     466         179 :     PetscCall(RGCreate(PetscObjectComm((PetscObject)pep),&pep->rg));
     467         179 :     PetscCall(PetscObjectIncrementTabLevel((PetscObject)pep->rg,(PetscObject)pep,0));
     468         179 :     PetscCall(PetscObjectSetOptions((PetscObject)pep->rg,((PetscObject)pep)->options));
     469             :   }
     470         206 :   *rg = pep->rg;
     471         206 :   PetscFunctionReturn(PETSC_SUCCESS);
     472             : }
     473             : 
     474             : /*@
     475             :    PEPSetDS - Associates a direct solver object to the polynomial eigensolver.
     476             : 
     477             :    Collective
     478             : 
     479             :    Input Parameters:
     480             : +  pep - eigensolver context obtained from PEPCreate()
     481             : -  ds  - the direct solver object
     482             : 
     483             :    Note:
     484             :    Use PEPGetDS() to retrieve the direct solver context (for example,
     485             :    to free it at the end of the computations).
     486             : 
     487             :    Level: advanced
     488             : 
     489             : .seealso: PEPGetDS()
     490             : @*/
     491           0 : PetscErrorCode PEPSetDS(PEP pep,DS ds)
     492             : {
     493           0 :   PetscFunctionBegin;
     494           0 :   PetscValidHeaderSpecific(pep,PEP_CLASSID,1);
     495           0 :   PetscValidHeaderSpecific(ds,DS_CLASSID,2);
     496           0 :   PetscCheckSameComm(pep,1,ds,2);
     497           0 :   PetscCall(PetscObjectReference((PetscObject)ds));
     498           0 :   PetscCall(DSDestroy(&pep->ds));
     499           0 :   pep->ds = ds;
     500           0 :   PetscFunctionReturn(PETSC_SUCCESS);
     501             : }
     502             : 
     503             : /*@
     504             :    PEPGetDS - Obtain the direct solver object associated to the
     505             :    polynomial eigensolver object.
     506             : 
     507             :    Not Collective
     508             : 
     509             :    Input Parameters:
     510             : .  pep - eigensolver context obtained from PEPCreate()
     511             : 
     512             :    Output Parameter:
     513             : .  ds - direct solver context
     514             : 
     515             :    Level: advanced
     516             : 
     517             : .seealso: PEPSetDS()
     518             : @*/
     519         182 : PetscErrorCode PEPGetDS(PEP pep,DS *ds)
     520             : {
     521         182 :   PetscFunctionBegin;
     522         182 :   PetscValidHeaderSpecific(pep,PEP_CLASSID,1);
     523         182 :   PetscAssertPointer(ds,2);
     524         182 :   if (!pep->ds) {
     525         182 :     PetscCall(DSCreate(PetscObjectComm((PetscObject)pep),&pep->ds));
     526         182 :     PetscCall(PetscObjectIncrementTabLevel((PetscObject)pep->ds,(PetscObject)pep,0));
     527         182 :     PetscCall(PetscObjectSetOptions((PetscObject)pep->ds,((PetscObject)pep)->options));
     528             :   }
     529         182 :   *ds = pep->ds;
     530         182 :   PetscFunctionReturn(PETSC_SUCCESS);
     531             : }
     532             : 
     533             : /*@
     534             :    PEPSetST - Associates a spectral transformation object to the eigensolver.
     535             : 
     536             :    Collective
     537             : 
     538             :    Input Parameters:
     539             : +  pep - eigensolver context obtained from PEPCreate()
     540             : -  st   - the spectral transformation object
     541             : 
     542             :    Note:
     543             :    Use PEPGetST() to retrieve the spectral transformation context (for example,
     544             :    to free it at the end of the computations).
     545             : 
     546             :    Level: advanced
     547             : 
     548             : .seealso: PEPGetST()
     549             : @*/
     550           1 : PetscErrorCode PEPSetST(PEP pep,ST st)
     551             : {
     552           1 :   PetscFunctionBegin;
     553           1 :   PetscValidHeaderSpecific(pep,PEP_CLASSID,1);
     554           1 :   PetscValidHeaderSpecific(st,ST_CLASSID,2);
     555           1 :   PetscCheckSameComm(pep,1,st,2);
     556           1 :   PetscCall(PetscObjectReference((PetscObject)st));
     557           1 :   PetscCall(STDestroy(&pep->st));
     558           1 :   pep->st = st;
     559           1 :   PetscFunctionReturn(PETSC_SUCCESS);
     560             : }
     561             : 
     562             : /*@
     563             :    PEPGetST - Obtain the spectral transformation (ST) object associated
     564             :    to the eigensolver object.
     565             : 
     566             :    Not Collective
     567             : 
     568             :    Input Parameters:
     569             : .  pep - eigensolver context obtained from PEPCreate()
     570             : 
     571             :    Output Parameter:
     572             : .  st - spectral transformation context
     573             : 
     574             :    Level: intermediate
     575             : 
     576             : .seealso: PEPSetST()
     577             : @*/
     578       42513 : PetscErrorCode PEPGetST(PEP pep,ST *st)
     579             : {
     580       42513 :   PetscFunctionBegin;
     581       42513 :   PetscValidHeaderSpecific(pep,PEP_CLASSID,1);
     582       42513 :   PetscAssertPointer(st,2);
     583       42513 :   if (!pep->st) {
     584         181 :     PetscCall(STCreate(PetscObjectComm((PetscObject)pep),&pep->st));
     585         181 :     PetscCall(PetscObjectIncrementTabLevel((PetscObject)pep->st,(PetscObject)pep,0));
     586         181 :     PetscCall(PetscObjectSetOptions((PetscObject)pep->st,((PetscObject)pep)->options));
     587             :   }
     588       42513 :   *st = pep->st;
     589       42513 :   PetscFunctionReturn(PETSC_SUCCESS);
     590             : }
     591             : 
     592             : /*@
     593             :    PEPRefineGetKSP - Obtain the ksp object used by the eigensolver
     594             :    object in the refinement phase.
     595             : 
     596             :    Collective
     597             : 
     598             :    Input Parameters:
     599             : .  pep - eigensolver context obtained from PEPCreate()
     600             : 
     601             :    Output Parameter:
     602             : .  ksp - ksp context
     603             : 
     604             :    Level: advanced
     605             : 
     606             : .seealso: PEPSetRefine()
     607             : @*/
     608         200 : PetscErrorCode PEPRefineGetKSP(PEP pep,KSP *ksp)
     609             : {
     610         200 :   MPI_Comm       comm;
     611             : 
     612         200 :   PetscFunctionBegin;
     613         200 :   PetscValidHeaderSpecific(pep,PEP_CLASSID,1);
     614         200 :   PetscAssertPointer(ksp,2);
     615         200 :   if (!pep->refineksp) {
     616         174 :     if (pep->npart>1) {
     617             :       /* Split in subcomunicators */
     618          12 :       PetscCall(PetscSubcommCreate(PetscObjectComm((PetscObject)pep),&pep->refinesubc));
     619          12 :       PetscCall(PetscSubcommSetNumber(pep->refinesubc,pep->npart));
     620          12 :       PetscCall(PetscSubcommSetType(pep->refinesubc,PETSC_SUBCOMM_CONTIGUOUS));
     621          12 :       PetscCall(PetscSubcommGetChild(pep->refinesubc,&comm));
     622         162 :     } else PetscCall(PetscObjectGetComm((PetscObject)pep,&comm));
     623         174 :     PetscCall(KSPCreate(comm,&pep->refineksp));
     624         174 :     PetscCall(PetscObjectIncrementTabLevel((PetscObject)pep->refineksp,(PetscObject)pep,0));
     625         174 :     PetscCall(PetscObjectSetOptions((PetscObject)pep->refineksp,((PetscObject)pep)->options));
     626         174 :     PetscCall(KSPSetOptionsPrefix(*ksp,((PetscObject)pep)->prefix));
     627         174 :     PetscCall(KSPAppendOptionsPrefix(*ksp,"pep_refine_"));
     628         347 :     PetscCall(KSPSetTolerances(pep->refineksp,SlepcDefaultTol(pep->rtol),PETSC_CURRENT,PETSC_CURRENT,PETSC_CURRENT));
     629             :   }
     630         200 :   *ksp = pep->refineksp;
     631         200 :   PetscFunctionReturn(PETSC_SUCCESS);
     632             : }
     633             : 
     634             : /*@
     635             :    PEPSetTarget - Sets the value of the target.
     636             : 
     637             :    Logically Collective
     638             : 
     639             :    Input Parameters:
     640             : +  pep    - eigensolver context
     641             : -  target - the value of the target
     642             : 
     643             :    Options Database Key:
     644             : .  -pep_target <scalar> - the value of the target
     645             : 
     646             :    Notes:
     647             :    The target is a scalar value used to determine the portion of the spectrum
     648             :    of interest. It is used in combination with PEPSetWhichEigenpairs().
     649             : 
     650             :    In the case of complex scalars, a complex value can be provided in the
     651             :    command line with [+/-][realnumber][+/-]realnumberi with no spaces, e.g.
     652             :    -pep_target 1.0+2.0i
     653             : 
     654             :    Level: intermediate
     655             : 
     656             : .seealso: PEPGetTarget(), PEPSetWhichEigenpairs()
     657             : @*/
     658          91 : PetscErrorCode PEPSetTarget(PEP pep,PetscScalar target)
     659             : {
     660          91 :   PetscFunctionBegin;
     661          91 :   PetscValidHeaderSpecific(pep,PEP_CLASSID,1);
     662         273 :   PetscValidLogicalCollectiveScalar(pep,target,2);
     663          91 :   pep->target = target;
     664          91 :   if (!pep->st) PetscCall(PEPGetST(pep,&pep->st));
     665          91 :   PetscCall(STSetDefaultShift(pep->st,target));
     666          91 :   PetscFunctionReturn(PETSC_SUCCESS);
     667             : }
     668             : 
     669             : /*@
     670             :    PEPGetTarget - Gets the value of the target.
     671             : 
     672             :    Not Collective
     673             : 
     674             :    Input Parameter:
     675             : .  pep - eigensolver context
     676             : 
     677             :    Output Parameter:
     678             : .  target - the value of the target
     679             : 
     680             :    Note:
     681             :    If the target was not set by the user, then zero is returned.
     682             : 
     683             :    Level: intermediate
     684             : 
     685             : .seealso: PEPSetTarget()
     686             : @*/
     687           2 : PetscErrorCode PEPGetTarget(PEP pep,PetscScalar* target)
     688             : {
     689           2 :   PetscFunctionBegin;
     690           2 :   PetscValidHeaderSpecific(pep,PEP_CLASSID,1);
     691           2 :   PetscAssertPointer(target,2);
     692           2 :   *target = pep->target;
     693           2 :   PetscFunctionReturn(PETSC_SUCCESS);
     694             : }
     695             : 
     696             : /*@
     697             :    PEPSetInterval - Defines the computational interval for spectrum slicing.
     698             : 
     699             :    Logically Collective
     700             : 
     701             :    Input Parameters:
     702             : +  pep  - eigensolver context
     703             : .  inta - left end of the interval
     704             : -  intb - right end of the interval
     705             : 
     706             :    Options Database Key:
     707             : .  -pep_interval <a,b> - set [a,b] as the interval of interest
     708             : 
     709             :    Notes:
     710             :    Spectrum slicing is a technique employed for computing all eigenvalues of
     711             :    symmetric eigenproblems in a given interval. This function provides the
     712             :    interval to be considered. It must be used in combination with PEP_ALL, see
     713             :    PEPSetWhichEigenpairs().
     714             : 
     715             :    In the command-line option, two values must be provided. For an open interval,
     716             :    one can give an infinite, e.g., -pep_interval 1.0,inf or -pep_interval -inf,1.0.
     717             :    An open interval in the programmatic interface can be specified with
     718             :    PETSC_MAX_REAL and -PETSC_MAX_REAL.
     719             : 
     720             :    Level: intermediate
     721             : 
     722             : .seealso: PEPGetInterval(), PEPSetWhichEigenpairs()
     723             : @*/
     724           9 : PetscErrorCode PEPSetInterval(PEP pep,PetscReal inta,PetscReal intb)
     725             : {
     726           9 :   PetscFunctionBegin;
     727           9 :   PetscValidHeaderSpecific(pep,PEP_CLASSID,1);
     728          27 :   PetscValidLogicalCollectiveReal(pep,inta,2);
     729          27 :   PetscValidLogicalCollectiveReal(pep,intb,3);
     730           9 :   PetscCheck(inta<intb,PetscObjectComm((PetscObject)pep),PETSC_ERR_ARG_WRONG,"Badly defined interval, must be inta<intb");
     731           9 :   if (pep->inta != inta || pep->intb != intb) {
     732           9 :     pep->inta = inta;
     733           9 :     pep->intb = intb;
     734           9 :     pep->state = PEP_STATE_INITIAL;
     735             :   }
     736           9 :   PetscFunctionReturn(PETSC_SUCCESS);
     737             : }
     738             : 
     739             : /*@
     740             :    PEPGetInterval - Gets the computational interval for spectrum slicing.
     741             : 
     742             :    Not Collective
     743             : 
     744             :    Input Parameter:
     745             : .  pep - eigensolver context
     746             : 
     747             :    Output Parameters:
     748             : +  inta - left end of the interval
     749             : -  intb - right end of the interval
     750             : 
     751             :    Level: intermediate
     752             : 
     753             :    Note:
     754             :    If the interval was not set by the user, then zeros are returned.
     755             : 
     756             : .seealso: PEPSetInterval()
     757             : @*/
     758           4 : PetscErrorCode PEPGetInterval(PEP pep,PetscReal* inta,PetscReal* intb)
     759             : {
     760           4 :   PetscFunctionBegin;
     761           4 :   PetscValidHeaderSpecific(pep,PEP_CLASSID,1);
     762           4 :   if (inta) *inta = pep->inta;
     763           4 :   if (intb) *intb = pep->intb;
     764           4 :   PetscFunctionReturn(PETSC_SUCCESS);
     765             : }

Generated by: LCOV version 1.14