LCOV - code coverage report
Current view: top level - eps/impls/davidson/jd - jd.c (source / functions) Hit Total Coverage
Test: SLEPc Lines: 233 259 90.0 %
Date: 2021-08-02 00:32:28 Functions: 23 24 95.8 %
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             :    SLEPc eigensolver: "jd"
      12             : 
      13             :    Method: Jacobi-Davidson
      14             : 
      15             :    Algorithm:
      16             : 
      17             :        Jacobi-Davidson with various subspace extraction and
      18             :        restart techniques.
      19             : 
      20             :    References:
      21             : 
      22             :        [1] G.L.G. Sleijpen and H.A. van der Vorst, "A Jacobi-Davidson
      23             :            iteration method for linear eigenvalue problems", SIAM J.
      24             :            Matrix Anal. Appl. 17(2):401-425, 1996.
      25             : 
      26             :        [2] E. Romero and J.E. Roman, "A parallel implementation of
      27             :            Davidson methods for large-scale eigenvalue problems in
      28             :            SLEPc", ACM Trans. Math. Software 40(2), Article 13, 2014.
      29             : */
      30             : 
      31             : #include <slepc/private/epsimpl.h>                /*I "slepceps.h" I*/
      32             : #include <../src/eps/impls/davidson/davidson.h>
      33             : 
      34          19 : PetscErrorCode EPSSetFromOptions_JD(PetscOptionItems *PetscOptionsObject,EPS eps)
      35             : {
      36          19 :   PetscErrorCode ierr;
      37          19 :   PetscBool      flg,flg2,op,orth;
      38          19 :   PetscInt       opi,opi0;
      39          19 :   PetscReal      opf;
      40             : 
      41          19 :   PetscFunctionBegin;
      42          19 :   ierr = PetscOptionsHead(PetscOptionsObject,"EPS Jacobi-Davidson (JD) Options");CHKERRQ(ierr);
      43             : 
      44          19 :     ierr = EPSJDGetKrylovStart(eps,&op);CHKERRQ(ierr);
      45          19 :     ierr = PetscOptionsBool("-eps_jd_krylov_start","Start the search subspace with a Krylov basis","EPSJDSetKrylovStart",op,&op,&flg);CHKERRQ(ierr);
      46          19 :     if (flg) { ierr = EPSJDSetKrylovStart(eps,op);CHKERRQ(ierr); }
      47             : 
      48          19 :     ierr = EPSJDGetBOrth(eps,&orth);CHKERRQ(ierr);
      49          19 :     ierr = PetscOptionsBool("-eps_jd_borth","Use B-orthogonalization in the search subspace","EPSJDSetBOrth",op,&op,&flg);CHKERRQ(ierr);
      50          19 :     if (flg) { ierr = EPSJDSetBOrth(eps,op);CHKERRQ(ierr); }
      51             : 
      52          19 :     ierr = EPSJDGetBlockSize(eps,&opi);CHKERRQ(ierr);
      53          19 :     ierr = PetscOptionsInt("-eps_jd_blocksize","Number of vectors to add to the search subspace","EPSJDSetBlockSize",opi,&opi,&flg);CHKERRQ(ierr);
      54          19 :     if (flg) { ierr = EPSJDSetBlockSize(eps,opi);CHKERRQ(ierr); }
      55             : 
      56          19 :     ierr = EPSJDGetRestart(eps,&opi,&opi0);CHKERRQ(ierr);
      57          19 :     ierr = PetscOptionsInt("-eps_jd_minv","Size of the search subspace after restarting","EPSJDSetRestart",opi,&opi,&flg);CHKERRQ(ierr);
      58          19 :     ierr = PetscOptionsInt("-eps_jd_plusk","Number of eigenvectors saved from the previous iteration when restarting","EPSJDSetRestart",opi0,&opi0,&flg2);CHKERRQ(ierr);
      59          19 :     if (flg || flg2) { ierr = EPSJDSetRestart(eps,opi,opi0);CHKERRQ(ierr); }
      60             : 
      61          19 :     ierr = EPSJDGetInitialSize(eps,&opi);CHKERRQ(ierr);
      62          19 :     ierr = PetscOptionsInt("-eps_jd_initial_size","Initial size of the search subspace","EPSJDSetInitialSize",opi,&opi,&flg);CHKERRQ(ierr);
      63          19 :     if (flg) { ierr = EPSJDSetInitialSize(eps,opi);CHKERRQ(ierr); }
      64             : 
      65          19 :     ierr = EPSJDGetFix(eps,&opf);CHKERRQ(ierr);
      66          19 :     ierr = PetscOptionsReal("-eps_jd_fix","Tolerance for changing the target in the correction equation","EPSJDSetFix",opf,&opf,&flg);CHKERRQ(ierr);
      67          19 :     if (flg) { ierr = EPSJDSetFix(eps,opf);CHKERRQ(ierr); }
      68             : 
      69          19 :     ierr = EPSJDGetConstCorrectionTol(eps,&op);CHKERRQ(ierr);
      70          19 :     ierr = PetscOptionsBool("-eps_jd_const_correction_tol","Disable the dynamic stopping criterion when solving the correction equation","EPSJDSetConstCorrectionTol",op,&op,&flg);CHKERRQ(ierr);
      71          19 :     if (flg) { ierr = EPSJDSetConstCorrectionTol(eps,op);CHKERRQ(ierr); }
      72             : 
      73          19 :   ierr = PetscOptionsTail();CHKERRQ(ierr);
      74          19 :   PetscFunctionReturn(0);
      75             : }
      76             : 
      77          49 : PetscErrorCode EPSSetDefaultST_JD(EPS eps)
      78             : {
      79          49 :   PetscErrorCode ierr;
      80          49 :   KSP            ksp;
      81             : 
      82          49 :   PetscFunctionBegin;
      83          49 :   if (!((PetscObject)eps->st)->type_name) {
      84          20 :     ierr = STSetType(eps->st,STPRECOND);CHKERRQ(ierr);
      85          20 :     ierr = STPrecondSetKSPHasMat(eps->st,PETSC_TRUE);CHKERRQ(ierr);
      86             :   }
      87          49 :   ierr = STGetKSP(eps->st,&ksp);CHKERRQ(ierr);
      88          49 :   if (!((PetscObject)ksp)->type_name) {
      89          20 :     ierr = KSPSetType(ksp,KSPBCGSL);CHKERRQ(ierr);
      90          20 :     ierr = KSPSetTolerances(ksp,1e-4,PETSC_DEFAULT,PETSC_DEFAULT,90);CHKERRQ(ierr);
      91             :   }
      92          49 :   PetscFunctionReturn(0);
      93             : }
      94             : 
      95          30 : PetscErrorCode EPSSetUp_JD(EPS eps)
      96             : {
      97          30 :   PetscErrorCode ierr;
      98          30 :   PetscBool      t;
      99          30 :   KSP            ksp;
     100             : 
     101          30 :   PetscFunctionBegin;
     102             :   /* Setup common for all davidson solvers */
     103          30 :   ierr = EPSSetUp_XD(eps);CHKERRQ(ierr);
     104             : 
     105             :   /* Check some constraints */
     106          30 :   ierr = STGetKSP(eps->st,&ksp);CHKERRQ(ierr);
     107          30 :   ierr = PetscObjectTypeCompare((PetscObject)ksp,KSPPREONLY,&t);CHKERRQ(ierr);
     108          30 :   if (t) SETERRQ(PetscObjectComm((PetscObject)eps),PETSC_ERR_SUP,"EPSJD does not work with KSPPREONLY");
     109          30 :   PetscFunctionReturn(0);
     110             : }
     111             : 
     112           0 : PetscErrorCode EPSView_JD(EPS eps,PetscViewer viewer)
     113             : {
     114           0 :   PetscErrorCode ierr;
     115           0 :   PetscBool      isascii,opb;
     116           0 :   PetscReal      opf;
     117           0 :   PetscInt       opi,opi0;
     118             : 
     119           0 :   PetscFunctionBegin;
     120           0 :   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&isascii);CHKERRQ(ierr);
     121           0 :   if (isascii) {
     122           0 :     ierr = EPSXDGetBOrth_XD(eps,&opb);CHKERRQ(ierr);
     123           0 :     if (opb) {
     124           0 :       ierr = PetscViewerASCIIPrintf(viewer,"  search subspace is B-orthogonalized\n");CHKERRQ(ierr);
     125             :     } else {
     126           0 :       ierr = PetscViewerASCIIPrintf(viewer,"  search subspace is orthogonalized\n");CHKERRQ(ierr);
     127             :     }
     128           0 :     ierr = EPSXDGetBlockSize_XD(eps,&opi);CHKERRQ(ierr);
     129           0 :     ierr = PetscViewerASCIIPrintf(viewer,"  block size=%D\n",opi);CHKERRQ(ierr);
     130           0 :     ierr = EPSXDGetKrylovStart_XD(eps,&opb);CHKERRQ(ierr);
     131           0 :     if (!opb) {
     132           0 :       ierr = PetscViewerASCIIPrintf(viewer,"  type of the initial subspace: non-Krylov\n");CHKERRQ(ierr);
     133             :     } else {
     134           0 :       ierr = PetscViewerASCIIPrintf(viewer,"  type of the initial subspace: Krylov\n");CHKERRQ(ierr);
     135             :     }
     136           0 :     ierr = EPSXDGetRestart_XD(eps,&opi,&opi0);CHKERRQ(ierr);
     137           0 :     ierr = PetscViewerASCIIPrintf(viewer,"  size of the subspace after restarting: %D\n",opi);CHKERRQ(ierr);
     138           0 :     ierr = PetscViewerASCIIPrintf(viewer,"  number of vectors after restarting from the previous iteration: %D\n",opi0);CHKERRQ(ierr);
     139             : 
     140           0 :     ierr = EPSJDGetFix_JD(eps,&opf);CHKERRQ(ierr);
     141           0 :     ierr = PetscViewerASCIIPrintf(viewer,"  threshold for changing the target in the correction equation (fix): %g\n",(double)opf);CHKERRQ(ierr);
     142             : 
     143           0 :     ierr = EPSJDGetConstCorrectionTol_JD(eps,&opb);CHKERRQ(ierr);
     144           0 :     if (!opb) { ierr = PetscViewerASCIIPrintf(viewer,"  using dynamic tolerance for the correction equation\n");CHKERRQ(ierr); }
     145             :   }
     146           0 :   PetscFunctionReturn(0);
     147             : }
     148             : 
     149          20 : PetscErrorCode EPSDestroy_JD(EPS eps)
     150             : {
     151          20 :   PetscErrorCode  ierr;
     152             : 
     153          20 :   PetscFunctionBegin;
     154          20 :   ierr = PetscFree(eps->data);CHKERRQ(ierr);
     155          20 :   ierr = PetscObjectComposeFunction((PetscObject)eps,"EPSJDSetKrylovStart_C",NULL);CHKERRQ(ierr);
     156          20 :   ierr = PetscObjectComposeFunction((PetscObject)eps,"EPSJDGetKrylovStart_C",NULL);CHKERRQ(ierr);
     157          20 :   ierr = PetscObjectComposeFunction((PetscObject)eps,"EPSJDSetBlockSize_C",NULL);CHKERRQ(ierr);
     158          20 :   ierr = PetscObjectComposeFunction((PetscObject)eps,"EPSJDGetBlockSize_C",NULL);CHKERRQ(ierr);
     159          20 :   ierr = PetscObjectComposeFunction((PetscObject)eps,"EPSJDSetRestart_C",NULL);CHKERRQ(ierr);
     160          20 :   ierr = PetscObjectComposeFunction((PetscObject)eps,"EPSJDGetRestart_C",NULL);CHKERRQ(ierr);
     161          20 :   ierr = PetscObjectComposeFunction((PetscObject)eps,"EPSJDSetInitialSize_C",NULL);CHKERRQ(ierr);
     162          20 :   ierr = PetscObjectComposeFunction((PetscObject)eps,"EPSJDGetInitialSize_C",NULL);CHKERRQ(ierr);
     163          20 :   ierr = PetscObjectComposeFunction((PetscObject)eps,"EPSJDSetFix_C",NULL);CHKERRQ(ierr);
     164          20 :   ierr = PetscObjectComposeFunction((PetscObject)eps,"EPSJDGetFix_C",NULL);CHKERRQ(ierr);
     165          20 :   ierr = PetscObjectComposeFunction((PetscObject)eps,"EPSJDSetConstCorrectionTol_C",NULL);CHKERRQ(ierr);
     166          20 :   ierr = PetscObjectComposeFunction((PetscObject)eps,"EPSJDGetConstCorrectionTol_C",NULL);CHKERRQ(ierr);
     167          20 :   ierr = PetscObjectComposeFunction((PetscObject)eps,"EPSJDSetBOrth_C",NULL);CHKERRQ(ierr);
     168          20 :   ierr = PetscObjectComposeFunction((PetscObject)eps,"EPSJDGetBOrth_C",NULL);CHKERRQ(ierr);
     169          20 :   PetscFunctionReturn(0);
     170             : }
     171             : 
     172             : /*@
     173             :    EPSJDSetKrylovStart - Activates or deactivates starting the searching
     174             :    subspace with a Krylov basis.
     175             : 
     176             :    Logically Collective on eps
     177             : 
     178             :    Input Parameters:
     179             : +  eps - the eigenproblem solver context
     180             : -  krylovstart - boolean flag
     181             : 
     182             :    Options Database Key:
     183             : .  -eps_jd_krylov_start - Activates starting the searching subspace with a
     184             :     Krylov basis
     185             : 
     186             :    Level: advanced
     187             : 
     188             : .seealso: EPSJDGetKrylovStart()
     189             : @*/
     190           1 : PetscErrorCode EPSJDSetKrylovStart(EPS eps,PetscBool krylovstart)
     191             : {
     192           1 :   PetscErrorCode ierr;
     193             : 
     194           1 :   PetscFunctionBegin;
     195           1 :   PetscValidHeaderSpecific(eps,EPS_CLASSID,1);
     196           2 :   PetscValidLogicalCollectiveBool(eps,krylovstart,2);
     197           1 :   ierr = PetscTryMethod(eps,"EPSJDSetKrylovStart_C",(EPS,PetscBool),(eps,krylovstart));CHKERRQ(ierr);
     198           1 :   PetscFunctionReturn(0);
     199             : }
     200             : 
     201             : /*@
     202             :    EPSJDGetKrylovStart - Returns a flag indicating if the searching subspace is started with a
     203             :    Krylov basis.
     204             : 
     205             :    Not Collective
     206             : 
     207             :    Input Parameter:
     208             : .  eps - the eigenproblem solver context
     209             : 
     210             :    Output Parameters:
     211             : .  krylovstart - boolean flag indicating if the searching subspace is started
     212             :    with a Krylov basis
     213             : 
     214             :    Level: advanced
     215             : 
     216             : .seealso: EPSJDGetKrylovStart()
     217             : @*/
     218          19 : PetscErrorCode EPSJDGetKrylovStart(EPS eps,PetscBool *krylovstart)
     219             : {
     220          19 :   PetscErrorCode ierr;
     221             : 
     222          19 :   PetscFunctionBegin;
     223          19 :   PetscValidHeaderSpecific(eps,EPS_CLASSID,1);
     224          19 :   PetscValidBoolPointer(krylovstart,2);
     225          19 :   ierr = PetscUseMethod(eps,"EPSJDGetKrylovStart_C",(EPS,PetscBool*),(eps,krylovstart));CHKERRQ(ierr);
     226          19 :   PetscFunctionReturn(0);
     227             : }
     228             : 
     229             : /*@
     230             :    EPSJDSetBlockSize - Sets the number of vectors to be added to the searching space
     231             :    in every iteration.
     232             : 
     233             :    Logically Collective on eps
     234             : 
     235             :    Input Parameters:
     236             : +  eps - the eigenproblem solver context
     237             : -  blocksize - number of vectors added to the search space in every iteration
     238             : 
     239             :    Options Database Key:
     240             : .  -eps_jd_blocksize - number of vectors added to the searching space every iteration
     241             : 
     242             :    Level: advanced
     243             : 
     244             : .seealso: EPSJDSetKrylovStart()
     245             : @*/
     246           1 : PetscErrorCode EPSJDSetBlockSize(EPS eps,PetscInt blocksize)
     247             : {
     248           1 :   PetscErrorCode ierr;
     249             : 
     250           1 :   PetscFunctionBegin;
     251           1 :   PetscValidHeaderSpecific(eps,EPS_CLASSID,1);
     252           2 :   PetscValidLogicalCollectiveInt(eps,blocksize,2);
     253           1 :   ierr = PetscTryMethod(eps,"EPSJDSetBlockSize_C",(EPS,PetscInt),(eps,blocksize));CHKERRQ(ierr);
     254           1 :   PetscFunctionReturn(0);
     255             : }
     256             : 
     257             : /*@
     258             :    EPSJDGetBlockSize - Returns the number of vectors to be added to the searching space
     259             :    in every iteration.
     260             : 
     261             :    Not Collective
     262             : 
     263             :    Input Parameter:
     264             : .  eps - the eigenproblem solver context
     265             : 
     266             :    Output Parameter:
     267             : .  blocksize - number of vectors added to the search space in every iteration
     268             : 
     269             :    Level: advanced
     270             : 
     271             : .seealso: EPSJDSetBlockSize()
     272             : @*/
     273          19 : PetscErrorCode EPSJDGetBlockSize(EPS eps,PetscInt *blocksize)
     274             : {
     275          19 :   PetscErrorCode ierr;
     276             : 
     277          19 :   PetscFunctionBegin;
     278          19 :   PetscValidHeaderSpecific(eps,EPS_CLASSID,1);
     279          19 :   PetscValidIntPointer(blocksize,2);
     280          19 :   ierr = PetscUseMethod(eps,"EPSJDGetBlockSize_C",(EPS,PetscInt*),(eps,blocksize));CHKERRQ(ierr);
     281          19 :   PetscFunctionReturn(0);
     282             : }
     283             : 
     284             : /*@
     285             :    EPSJDSetRestart - Sets the number of vectors of the searching space after
     286             :    restarting and the number of vectors saved from the previous iteration.
     287             : 
     288             :    Logically Collective on eps
     289             : 
     290             :    Input Parameters:
     291             : +  eps - the eigenproblem solver context
     292             : .  minv - number of vectors of the searching subspace after restarting
     293             : -  plusk - number of vectors saved from the previous iteration
     294             : 
     295             :    Options Database Keys:
     296             : +  -eps_jd_minv - number of vectors of the searching subspace after restarting
     297             : -  -eps_jd_plusk - number of vectors saved from the previous iteration
     298             : 
     299             :    Level: advanced
     300             : 
     301             : .seealso: EPSJDGetRestart()
     302             : @*/
     303           2 : PetscErrorCode EPSJDSetRestart(EPS eps,PetscInt minv,PetscInt plusk)
     304             : {
     305           2 :   PetscErrorCode ierr;
     306             : 
     307           2 :   PetscFunctionBegin;
     308           2 :   PetscValidHeaderSpecific(eps,EPS_CLASSID,1);
     309           4 :   PetscValidLogicalCollectiveInt(eps,minv,2);
     310           4 :   PetscValidLogicalCollectiveInt(eps,plusk,3);
     311           2 :   ierr = PetscTryMethod(eps,"EPSJDSetRestart_C",(EPS,PetscInt,PetscInt),(eps,minv,plusk));CHKERRQ(ierr);
     312           2 :   PetscFunctionReturn(0);
     313             : }
     314             : 
     315             : /*@
     316             :    EPSJDGetRestart - Gets the number of vectors of the searching space after
     317             :    restarting and the number of vectors saved from the previous iteration.
     318             : 
     319             :    Not Collective
     320             : 
     321             :    Input Parameter:
     322             : .  eps - the eigenproblem solver context
     323             : 
     324             :    Output Parameters:
     325             : +  minv - number of vectors of the searching subspace after restarting
     326             : -  plusk - number of vectors saved from the previous iteration
     327             : 
     328             :    Level: advanced
     329             : 
     330             : .seealso: EPSJDSetRestart()
     331             : @*/
     332          19 : PetscErrorCode EPSJDGetRestart(EPS eps,PetscInt *minv,PetscInt *plusk)
     333             : {
     334          19 :   PetscErrorCode ierr;
     335             : 
     336          19 :   PetscFunctionBegin;
     337          19 :   PetscValidHeaderSpecific(eps,EPS_CLASSID,1);
     338          19 :   ierr = PetscUseMethod(eps,"EPSJDGetRestart_C",(EPS,PetscInt*,PetscInt*),(eps,minv,plusk));CHKERRQ(ierr);
     339          19 :   PetscFunctionReturn(0);
     340             : }
     341             : 
     342             : /*@
     343             :    EPSJDSetInitialSize - Sets the initial size of the searching space.
     344             : 
     345             :    Logically Collective on eps
     346             : 
     347             :    Input Parameters:
     348             : +  eps - the eigenproblem solver context
     349             : -  initialsize - number of vectors of the initial searching subspace
     350             : 
     351             :    Options Database Key:
     352             : .  -eps_jd_initial_size - number of vectors of the initial searching subspace
     353             : 
     354             :    Notes:
     355             :    If EPSJDGetKrylovStart() is PETSC_FALSE and the user provides vectors with
     356             :    EPSSetInitialSpace(), up to initialsize vectors will be used; and if the
     357             :    provided vectors are not enough, the solver completes the subspace with
     358             :    random vectors. In the case of EPSJDGetKrylovStart() being PETSC_TRUE, the solver
     359             :    gets the first vector provided by the user or, if not available, a random vector,
     360             :    and expands the Krylov basis up to initialsize vectors.
     361             : 
     362             :    Level: advanced
     363             : 
     364             : .seealso: EPSJDGetInitialSize(), EPSJDGetKrylovStart()
     365             : @*/
     366           1 : PetscErrorCode EPSJDSetInitialSize(EPS eps,PetscInt initialsize)
     367             : {
     368           1 :   PetscErrorCode ierr;
     369             : 
     370           1 :   PetscFunctionBegin;
     371           1 :   PetscValidHeaderSpecific(eps,EPS_CLASSID,1);
     372           2 :   PetscValidLogicalCollectiveInt(eps,initialsize,2);
     373           1 :   ierr = PetscTryMethod(eps,"EPSJDSetInitialSize_C",(EPS,PetscInt),(eps,initialsize));CHKERRQ(ierr);
     374           1 :   PetscFunctionReturn(0);
     375             : }
     376             : 
     377             : /*@
     378             :    EPSJDGetInitialSize - Returns the initial size of the searching space.
     379             : 
     380             :    Not Collective
     381             : 
     382             :    Input Parameter:
     383             : .  eps - the eigenproblem solver context
     384             : 
     385             :    Output Parameter:
     386             : .  initialsize - number of vectors of the initial searching subspace
     387             : 
     388             :    Notes:
     389             :    If EPSJDGetKrylovStart() is PETSC_FALSE and the user provides vectors with
     390             :    EPSSetInitialSpace(), up to initialsize vectors will be used; and if the
     391             :    provided vectors are not enough, the solver completes the subspace with
     392             :    random vectors. In the case of EPSJDGetKrylovStart() being PETSC_TRUE, the solver
     393             :    gets the first vector provided by the user or, if not available, a random vector,
     394             :    and expands the Krylov basis up to initialsize vectors.
     395             : 
     396             :    Level: advanced
     397             : 
     398             : .seealso: EPSJDSetInitialSize(), EPSJDGetKrylovStart()
     399             : @*/
     400          19 : PetscErrorCode EPSJDGetInitialSize(EPS eps,PetscInt *initialsize)
     401             : {
     402          19 :   PetscErrorCode ierr;
     403             : 
     404          19 :   PetscFunctionBegin;
     405          19 :   PetscValidHeaderSpecific(eps,EPS_CLASSID,1);
     406          19 :   PetscValidIntPointer(initialsize,2);
     407          19 :   ierr = PetscUseMethod(eps,"EPSJDGetInitialSize_C",(EPS,PetscInt*),(eps,initialsize));CHKERRQ(ierr);
     408          19 :   PetscFunctionReturn(0);
     409             : }
     410             : 
     411           1 : PetscErrorCode EPSJDSetFix_JD(EPS eps,PetscReal fix)
     412             : {
     413           1 :   EPS_DAVIDSON *data = (EPS_DAVIDSON*)eps->data;
     414             : 
     415           1 :   PetscFunctionBegin;
     416           1 :   if (fix == PETSC_DEFAULT || fix == PETSC_DECIDE) fix = 0.01;
     417           1 :   if (fix < 0.0) SETERRQ(PetscObjectComm((PetscObject)eps),PETSC_ERR_ARG_OUTOFRANGE,"Invalid fix value");
     418           1 :   data->fix = fix;
     419           1 :   PetscFunctionReturn(0);
     420             : }
     421             : 
     422             : /*@
     423             :    EPSJDSetFix - Sets the threshold for changing the target in the correction
     424             :    equation.
     425             : 
     426             :    Logically Collective on eps
     427             : 
     428             :    Input Parameters:
     429             : +  eps - the eigenproblem solver context
     430             : -  fix - threshold for changing the target
     431             : 
     432             :    Options Database Key:
     433             : .  -eps_jd_fix - the fix value
     434             : 
     435             :    Note:
     436             :    The target in the correction equation is fixed at the first iterations.
     437             :    When the norm of the residual vector is lower than the fix value,
     438             :    the target is set to the corresponding eigenvalue.
     439             : 
     440             :    Level: advanced
     441             : 
     442             : .seealso: EPSJDGetFix()
     443             : @*/
     444           1 : PetscErrorCode EPSJDSetFix(EPS eps,PetscReal fix)
     445             : {
     446           1 :   PetscErrorCode ierr;
     447             : 
     448           1 :   PetscFunctionBegin;
     449           1 :   PetscValidHeaderSpecific(eps,EPS_CLASSID,1);
     450           2 :   PetscValidLogicalCollectiveReal(eps,fix,2);
     451           1 :   ierr = PetscTryMethod(eps,"EPSJDSetFix_C",(EPS,PetscReal),(eps,fix));CHKERRQ(ierr);
     452           1 :   PetscFunctionReturn(0);
     453             : }
     454             : 
     455          19 : PetscErrorCode EPSJDGetFix_JD(EPS eps,PetscReal *fix)
     456             : {
     457          19 :   EPS_DAVIDSON *data = (EPS_DAVIDSON*)eps->data;
     458             : 
     459          19 :   PetscFunctionBegin;
     460          19 :   *fix = data->fix;
     461          19 :   PetscFunctionReturn(0);
     462             : }
     463             : 
     464             : /*@
     465             :    EPSJDGetFix - Returns the threshold for changing the target in the correction
     466             :    equation.
     467             : 
     468             :    Not Collective
     469             : 
     470             :    Input Parameter:
     471             : .  eps - the eigenproblem solver context
     472             : 
     473             :    Output Parameter:
     474             : .  fix - threshold for changing the target
     475             : 
     476             :    Note:
     477             :    The target in the correction equation is fixed at the first iterations.
     478             :    When the norm of the residual vector is lower than the fix value,
     479             :    the target is set to the corresponding eigenvalue.
     480             : 
     481             :    Level: advanced
     482             : 
     483             : .seealso: EPSJDSetFix()
     484             : @*/
     485          19 : PetscErrorCode EPSJDGetFix(EPS eps,PetscReal *fix)
     486             : {
     487          19 :   PetscErrorCode ierr;
     488             : 
     489          19 :   PetscFunctionBegin;
     490          19 :   PetscValidHeaderSpecific(eps,EPS_CLASSID,1);
     491          19 :   PetscValidRealPointer(fix,2);
     492          19 :   ierr = PetscUseMethod(eps,"EPSJDGetFix_C",(EPS,PetscReal*),(eps,fix));CHKERRQ(ierr);
     493          19 :   PetscFunctionReturn(0);
     494             : }
     495             : 
     496           1 : PetscErrorCode EPSJDSetConstCorrectionTol_JD(EPS eps,PetscBool constant)
     497             : {
     498           1 :   EPS_DAVIDSON *data = (EPS_DAVIDSON*)eps->data;
     499             : 
     500           1 :   PetscFunctionBegin;
     501           1 :   data->dynamic = PetscNot(constant);
     502           1 :   PetscFunctionReturn(0);
     503             : }
     504             : 
     505             : /*@
     506             :    EPSJDSetConstCorrectionTol - If true, deactivates the dynamic stopping criterion
     507             :    (also called Newton) that sets the KSP relative tolerance
     508             :    to 0.5**i, where i is the number of EPS iterations from the last converged value.
     509             : 
     510             :    Logically Collective on eps
     511             : 
     512             :    Input Parameters:
     513             : +  eps - the eigenproblem solver context
     514             : -  constant - if false, the KSP relative tolerance is set to 0.5**i.
     515             : 
     516             :    Options Database Key:
     517             : .  -eps_jd_const_correction_tol - Deactivates the dynamic stopping criterion.
     518             : 
     519             :    Level: advanced
     520             : 
     521             : .seealso: EPSJDGetConstCorrectionTol()
     522             : @*/
     523           1 : PetscErrorCode EPSJDSetConstCorrectionTol(EPS eps,PetscBool constant)
     524             : {
     525           1 :   PetscErrorCode ierr;
     526             : 
     527           1 :   PetscFunctionBegin;
     528           1 :   PetscValidHeaderSpecific(eps,EPS_CLASSID,1);
     529           2 :   PetscValidLogicalCollectiveBool(eps,constant,2);
     530           1 :   ierr = PetscTryMethod(eps,"EPSJDSetConstCorrectionTol_C",(EPS,PetscBool),(eps,constant));CHKERRQ(ierr);
     531           1 :   PetscFunctionReturn(0);
     532             : }
     533             : 
     534          19 : PetscErrorCode EPSJDGetConstCorrectionTol_JD(EPS eps,PetscBool *constant)
     535             : {
     536          19 :   EPS_DAVIDSON *data = (EPS_DAVIDSON*)eps->data;
     537             : 
     538          19 :   PetscFunctionBegin;
     539          19 :   *constant = PetscNot(data->dynamic);
     540          19 :   PetscFunctionReturn(0);
     541             : }
     542             : 
     543             : /*@
     544             :    EPSJDGetConstCorrectionTol - Returns a flag indicating if the dynamic stopping is being used for
     545             :    solving the correction equation. If the flag is false the KSP relative tolerance is set
     546             :    to 0.5**i, where i is the number of EPS iterations from the last converged value.
     547             : 
     548             :    Not Collective
     549             : 
     550             :    Input Parameter:
     551             : .  eps - the eigenproblem solver context
     552             : 
     553             :    Output Parameters:
     554             : .  constant - boolean flag indicating if the dynamic stopping criterion is not being used.
     555             : 
     556             :    Level: advanced
     557             : 
     558             : .seealso: EPSJDGetConstCorrectionTol()
     559             : @*/
     560          19 : PetscErrorCode EPSJDGetConstCorrectionTol(EPS eps,PetscBool *constant)
     561             : {
     562          19 :   PetscErrorCode ierr;
     563             : 
     564          19 :   PetscFunctionBegin;
     565          19 :   PetscValidHeaderSpecific(eps,EPS_CLASSID,1);
     566          19 :   PetscValidBoolPointer(constant,2);
     567          19 :   ierr = PetscUseMethod(eps,"EPSJDGetConstCorrectionTol_C",(EPS,PetscBool*),(eps,constant));CHKERRQ(ierr);
     568          19 :   PetscFunctionReturn(0);
     569             : }
     570             : 
     571             : /*@
     572             :    EPSJDSetBOrth - Selects the orthogonalization that will be used in the search
     573             :    subspace in case of generalized Hermitian problems.
     574             : 
     575             :    Logically Collective on eps
     576             : 
     577             :    Input Parameters:
     578             : +  eps   - the eigenproblem solver context
     579             : -  borth - whether to B-orthogonalize the search subspace
     580             : 
     581             :    Options Database Key:
     582             : .  -eps_jd_borth - Set the orthogonalization used in the search subspace
     583             : 
     584             :    Level: advanced
     585             : 
     586             : .seealso: EPSJDGetBOrth()
     587             : @*/
     588           1 : PetscErrorCode EPSJDSetBOrth(EPS eps,PetscBool borth)
     589             : {
     590           1 :   PetscErrorCode ierr;
     591             : 
     592           1 :   PetscFunctionBegin;
     593           1 :   PetscValidHeaderSpecific(eps,EPS_CLASSID,1);
     594           2 :   PetscValidLogicalCollectiveBool(eps,borth,2);
     595           1 :   ierr = PetscTryMethod(eps,"EPSJDSetBOrth_C",(EPS,PetscBool),(eps,borth));CHKERRQ(ierr);
     596           1 :   PetscFunctionReturn(0);
     597             : }
     598             : 
     599             : /*@
     600             :    EPSJDGetBOrth - Returns the orthogonalization used in the search
     601             :    subspace in case of generalized Hermitian problems.
     602             : 
     603             :    Not Collective
     604             : 
     605             :    Input Parameter:
     606             : .  eps - the eigenproblem solver context
     607             : 
     608             :    Output Parameters:
     609             : .  borth - whether to B-orthogonalize the search subspace
     610             : 
     611             :    Level: advanced
     612             : 
     613             : .seealso: EPSJDSetBOrth()
     614             : @*/
     615          19 : PetscErrorCode EPSJDGetBOrth(EPS eps,PetscBool *borth)
     616             : {
     617          19 :   PetscErrorCode ierr;
     618             : 
     619          19 :   PetscFunctionBegin;
     620          19 :   PetscValidHeaderSpecific(eps,EPS_CLASSID,1);
     621          19 :   PetscValidBoolPointer(borth,2);
     622          19 :   ierr = PetscUseMethod(eps,"EPSJDGetBOrth_C",(EPS,PetscBool*),(eps,borth));CHKERRQ(ierr);
     623          19 :   PetscFunctionReturn(0);
     624             : }
     625             : 
     626          20 : SLEPC_EXTERN PetscErrorCode EPSCreate_JD(EPS eps)
     627             : {
     628          20 :   PetscErrorCode ierr;
     629          20 :   EPS_DAVIDSON   *data;
     630             : 
     631          20 :   PetscFunctionBegin;
     632          20 :   ierr = PetscNewLog(eps,&data);CHKERRQ(ierr);
     633          20 :   eps->data = (void*)data;
     634             : 
     635          20 :   data->blocksize   = 1;
     636          20 :   data->initialsize = 6;
     637          20 :   data->minv        = 6;
     638          20 :   data->plusk       = PETSC_DEFAULT;
     639          20 :   data->ipB         = PETSC_TRUE;
     640          20 :   data->fix         = 0.01;
     641          20 :   data->krylovstart = PETSC_FALSE;
     642          20 :   data->dynamic     = PETSC_FALSE;
     643             : 
     644          20 :   eps->useds = PETSC_TRUE;
     645          20 :   eps->categ = EPS_CATEGORY_PRECOND;
     646             : 
     647          20 :   eps->ops->solve          = EPSSolve_XD;
     648          20 :   eps->ops->setup          = EPSSetUp_JD;
     649          20 :   eps->ops->setupsort      = EPSSetUpSort_Default;
     650          20 :   eps->ops->setfromoptions = EPSSetFromOptions_JD;
     651          20 :   eps->ops->destroy        = EPSDestroy_JD;
     652          20 :   eps->ops->reset          = EPSReset_XD;
     653          20 :   eps->ops->view           = EPSView_JD;
     654          20 :   eps->ops->backtransform  = EPSBackTransform_Default;
     655          20 :   eps->ops->computevectors = EPSComputeVectors_XD;
     656          20 :   eps->ops->setdefaultst   = EPSSetDefaultST_JD;
     657             : 
     658          20 :   ierr = PetscObjectComposeFunction((PetscObject)eps,"EPSJDSetKrylovStart_C",EPSXDSetKrylovStart_XD);CHKERRQ(ierr);
     659          20 :   ierr = PetscObjectComposeFunction((PetscObject)eps,"EPSJDGetKrylovStart_C",EPSXDGetKrylovStart_XD);CHKERRQ(ierr);
     660          20 :   ierr = PetscObjectComposeFunction((PetscObject)eps,"EPSJDSetBlockSize_C",EPSXDSetBlockSize_XD);CHKERRQ(ierr);
     661          20 :   ierr = PetscObjectComposeFunction((PetscObject)eps,"EPSJDGetBlockSize_C",EPSXDGetBlockSize_XD);CHKERRQ(ierr);
     662          20 :   ierr = PetscObjectComposeFunction((PetscObject)eps,"EPSJDSetRestart_C",EPSXDSetRestart_XD);CHKERRQ(ierr);
     663          20 :   ierr = PetscObjectComposeFunction((PetscObject)eps,"EPSJDGetRestart_C",EPSXDGetRestart_XD);CHKERRQ(ierr);
     664          20 :   ierr = PetscObjectComposeFunction((PetscObject)eps,"EPSJDSetInitialSize_C",EPSXDSetInitialSize_XD);CHKERRQ(ierr);
     665          20 :   ierr = PetscObjectComposeFunction((PetscObject)eps,"EPSJDGetInitialSize_C",EPSXDGetInitialSize_XD);CHKERRQ(ierr);
     666          20 :   ierr = PetscObjectComposeFunction((PetscObject)eps,"EPSJDSetFix_C",EPSJDSetFix_JD);CHKERRQ(ierr);
     667          20 :   ierr = PetscObjectComposeFunction((PetscObject)eps,"EPSJDGetFix_C",EPSJDGetFix_JD);CHKERRQ(ierr);
     668          20 :   ierr = PetscObjectComposeFunction((PetscObject)eps,"EPSJDSetConstCorrectionTol_C",EPSJDSetConstCorrectionTol_JD);CHKERRQ(ierr);
     669          20 :   ierr = PetscObjectComposeFunction((PetscObject)eps,"EPSJDGetConstCorrectionTol_C",EPSJDGetConstCorrectionTol_JD);CHKERRQ(ierr);
     670          20 :   ierr = PetscObjectComposeFunction((PetscObject)eps,"EPSJDSetBOrth_C",EPSXDSetBOrth_XD);CHKERRQ(ierr);
     671          20 :   ierr = PetscObjectComposeFunction((PetscObject)eps,"EPSJDGetBOrth_C",EPSXDGetBOrth_XD);CHKERRQ(ierr);
     672          20 :   PetscFunctionReturn(0);
     673             : }
     674             : 

Generated by: LCOV version 1.14