LCOV - code coverage report
Current view: top level - pep/tutorials/nlevp - butterfly.c (source / functions) Hit Total Coverage
Test: SLEPc Lines: 64 68 94.1 %
Date: 2024-12-18 00:51:33 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       3             :    SLEPc - Scalable Library for Eigenvalue Problem Computations
       4             :    Copyright (c) 2002-, 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             :    This example implements one of the problems found at
      12             :        NLEVP: A Collection of Nonlinear Eigenvalue Problems,
      13             :        The University of Manchester.
      14             :    The details of the collection can be found at:
      15             :        [1] T. Betcke et al., "NLEVP: A Collection of Nonlinear Eigenvalue
      16             :            Problems", ACM Trans. Math. Software 39(2), Article 7, 2013.
      17             : 
      18             :    The butterfly problem is a quartic PEP with T-even structure.
      19             : */
      20             : 
      21             : static char help[] = "Quartic polynomial eigenproblem with T-even structure.\n\n"
      22             :   "The command line options are:\n"
      23             :   "  -m <m>, grid size, the dimension of the matrices is n=m*m.\n"
      24             :   "  -c <array>, problem parameters, must be 10 comma-separated real values.\n\n";
      25             : 
      26             : #include <slepcpep.h>
      27             : 
      28             : #define NMAT 5
      29             : 
      30          12 : int main(int argc,char **argv)
      31             : {
      32          12 :   Mat            A[NMAT];         /* problem matrices */
      33          12 :   PEP            pep;             /* polynomial eigenproblem solver context */
      34          12 :   PetscInt       n,m=8,k,II,Istart,Iend,i,j;
      35          12 :   PetscReal      c[10] = { 0.6, 1.3, 1.3, 0.1, 0.1, 1.2, 1.0, 1.0, 1.2, 1.0 };
      36          12 :   PetscBool      flg;
      37          12 :   PetscBool      terse;
      38             : 
      39          12 :   PetscFunctionBeginUser;
      40          12 :   PetscCall(SlepcInitialize(&argc,&argv,NULL,help));
      41             : 
      42          12 :   PetscCall(PetscOptionsGetInt(NULL,NULL,"-m",&m,NULL));
      43          12 :   n = m*m;
      44          12 :   k = 10;
      45          12 :   PetscCall(PetscOptionsGetRealArray(NULL,NULL,"-c",c,&k,&flg));
      46          12 :   PetscCheck(!flg || k==10,PETSC_COMM_WORLD,PETSC_ERR_USER,"The number of parameters -c should be 10, you provided %" PetscInt_FMT,k);
      47          12 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD,"\nButterfly problem, n=%" PetscInt_FMT " (m=%" PetscInt_FMT ")\n\n",n,m));
      48             : 
      49             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      50             :                      Compute the polynomial matrices
      51             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
      52             : 
      53             :   /* initialize matrices */
      54          72 :   for (i=0;i<NMAT;i++) {
      55          60 :     PetscCall(MatCreate(PETSC_COMM_WORLD,&A[i]));
      56          60 :     PetscCall(MatSetSizes(A[i],PETSC_DECIDE,PETSC_DECIDE,n,n));
      57          60 :     PetscCall(MatSetFromOptions(A[i]));
      58             :   }
      59          12 :   PetscCall(MatGetOwnershipRange(A[0],&Istart,&Iend));
      60             : 
      61             :   /* A0 */
      62         716 :   for (II=Istart;II<Iend;II++) {
      63         704 :     i = II/m; j = II-i*m;
      64         704 :     PetscCall(MatSetValue(A[0],II,II,4.0*c[0]/6.0+4.0*c[1]/6.0,INSERT_VALUES));
      65         704 :     if (j>0) PetscCall(MatSetValue(A[0],II,II-1,c[0]/6.0,INSERT_VALUES));
      66         704 :     if (j<m-1) PetscCall(MatSetValue(A[0],II,II+1,c[0]/6.0,INSERT_VALUES));
      67         704 :     if (i>0) PetscCall(MatSetValue(A[0],II,II-m,c[1]/6.0,INSERT_VALUES));
      68         704 :     if (i<m-1) PetscCall(MatSetValue(A[0],II,II+m,c[1]/6.0,INSERT_VALUES));
      69             :   }
      70             : 
      71             :   /* A1 */
      72         716 :   for (II=Istart;II<Iend;II++) {
      73         704 :     i = II/m; j = II-i*m;
      74         704 :     if (j>0) PetscCall(MatSetValue(A[1],II,II-1,c[2],INSERT_VALUES));
      75         704 :     if (j<m-1) PetscCall(MatSetValue(A[1],II,II+1,-c[2],INSERT_VALUES));
      76         704 :     if (i>0) PetscCall(MatSetValue(A[1],II,II-m,c[3],INSERT_VALUES));
      77         704 :     if (i<m-1) PetscCall(MatSetValue(A[1],II,II+m,-c[3],INSERT_VALUES));
      78             :   }
      79             : 
      80             :   /* A2 */
      81         716 :   for (II=Istart;II<Iend;II++) {
      82         704 :     i = II/m; j = II-i*m;
      83         704 :     PetscCall(MatSetValue(A[2],II,II,-2.0*c[4]-2.0*c[5],INSERT_VALUES));
      84         704 :     if (j>0) PetscCall(MatSetValue(A[2],II,II-1,c[4],INSERT_VALUES));
      85         704 :     if (j<m-1) PetscCall(MatSetValue(A[2],II,II+1,c[4],INSERT_VALUES));
      86         704 :     if (i>0) PetscCall(MatSetValue(A[2],II,II-m,c[5],INSERT_VALUES));
      87         704 :     if (i<m-1) PetscCall(MatSetValue(A[2],II,II+m,c[5],INSERT_VALUES));
      88             :   }
      89             : 
      90             :   /* A3 */
      91         716 :   for (II=Istart;II<Iend;II++) {
      92         704 :     i = II/m; j = II-i*m;
      93         704 :     if (j>0) PetscCall(MatSetValue(A[3],II,II-1,c[6],INSERT_VALUES));
      94         704 :     if (j<m-1) PetscCall(MatSetValue(A[3],II,II+1,-c[6],INSERT_VALUES));
      95         704 :     if (i>0) PetscCall(MatSetValue(A[3],II,II-m,c[7],INSERT_VALUES));
      96         704 :     if (i<m-1) PetscCall(MatSetValue(A[3],II,II+m,-c[7],INSERT_VALUES));
      97             :   }
      98             : 
      99             :   /* A4 */
     100         716 :   for (II=Istart;II<Iend;II++) {
     101         704 :     i = II/m; j = II-i*m;
     102         704 :     PetscCall(MatSetValue(A[4],II,II,2.0*c[8]+2.0*c[9],INSERT_VALUES));
     103         704 :     if (j>0) PetscCall(MatSetValue(A[4],II,II-1,-c[8],INSERT_VALUES));
     104         704 :     if (j<m-1) PetscCall(MatSetValue(A[4],II,II+1,-c[8],INSERT_VALUES));
     105         704 :     if (i>0) PetscCall(MatSetValue(A[4],II,II-m,-c[9],INSERT_VALUES));
     106         704 :     if (i<m-1) PetscCall(MatSetValue(A[4],II,II+m,-c[9],INSERT_VALUES));
     107             :   }
     108             : 
     109             :   /* assemble matrices */
     110          72 :   for (i=0;i<NMAT;i++) PetscCall(MatAssemblyBegin(A[i],MAT_FINAL_ASSEMBLY));
     111          72 :   for (i=0;i<NMAT;i++) PetscCall(MatAssemblyEnd(A[i],MAT_FINAL_ASSEMBLY));
     112             : 
     113             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     114             :                 Create the eigensolver and solve the problem
     115             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     116             : 
     117          12 :   PetscCall(PEPCreate(PETSC_COMM_WORLD,&pep));
     118          12 :   PetscCall(PEPSetOperators(pep,NMAT,A));
     119          12 :   PetscCall(PEPSetFromOptions(pep));
     120          12 :   PetscCall(PEPSolve(pep));
     121             : 
     122             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     123             :                     Display solution and clean up
     124             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     125             : 
     126             :   /* show detailed info unless -terse option is given by user */
     127          12 :   PetscCall(PetscOptionsHasName(NULL,NULL,"-terse",&terse));
     128          12 :   if (terse) PetscCall(PEPErrorView(pep,PEP_ERROR_BACKWARD,NULL));
     129             :   else {
     130           0 :     PetscCall(PetscViewerPushFormat(PETSC_VIEWER_STDOUT_WORLD,PETSC_VIEWER_ASCII_INFO_DETAIL));
     131           0 :     PetscCall(PEPConvergedReasonView(pep,PETSC_VIEWER_STDOUT_WORLD));
     132           0 :     PetscCall(PEPErrorView(pep,PEP_ERROR_BACKWARD,PETSC_VIEWER_STDOUT_WORLD));
     133           0 :     PetscCall(PetscViewerPopFormat(PETSC_VIEWER_STDOUT_WORLD));
     134             :   }
     135          12 :   PetscCall(PEPDestroy(&pep));
     136          72 :   for (i=0;i<NMAT;i++) PetscCall(MatDestroy(&A[i]));
     137          12 :   PetscCall(SlepcFinalize());
     138             :   return 0;
     139             : }
     140             : 
     141             : /*TEST
     142             : 
     143             :    testset:
     144             :       args: -pep_nev 4 -st_type sinvert -pep_target 0.01 -terse
     145             :       output_file: output/butterfly_1.out
     146             :       test:
     147             :          suffix: 1_toar
     148             :          args: -pep_type toar -pep_toar_restart 0.3
     149             :       test:
     150             :          suffix: 1_linear
     151             :          args: -pep_type linear
     152             : 
     153             :    test:
     154             :       suffix: 2
     155             :       args: -pep_type {{toar linear}} -pep_nev 4 -terse
     156             :       requires: double
     157             : 
     158             :    testset:
     159             :       args: -pep_type ciss -rg_type ellipse -rg_ellipse_center 1+.5i -rg_ellipse_radius .15 -terse
     160             :       requires: complex
     161             :       filter: sed -e "s/95386/95385/" | sed -e "s/91010/91009/" | sed -e "s/93092/93091/" | sed -e "s/96723/96724/" | sed -e "s/43015/43016/" | sed -e "s/53513/53514/"
     162             :       output_file: output/butterfly_ciss.out
     163             :       timeoutfactor: 2
     164             :       test:
     165             :          suffix: ciss_hankel
     166             :          args: -pep_ciss_extraction hankel -pep_ciss_integration_points 60
     167             :          requires: !single
     168             :       test:
     169             :          suffix: ciss_ritz
     170             :          args: -pep_ciss_extraction ritz
     171             :       test:
     172             :          suffix: ciss_caa
     173             :          args: -pep_ciss_extraction caa -pep_ciss_moments 4
     174             :       test:
     175             :          suffix: ciss_part
     176             :          nsize: 2
     177             :          args: -pep_ciss_partitions 2
     178             :       test:
     179             :          suffix: ciss_refine
     180             :          args: -pep_ciss_refine_inner 1 -pep_ciss_refine_blocksize 1
     181             : 
     182             :    testset:
     183             :       args: -pep_type ciss -rg_type ellipse -rg_ellipse_center .5+.5i -rg_ellipse_radius .25 -pep_ciss_moments 4 -pep_ciss_blocksize 5 -pep_ciss_refine_blocksize 2 -terse
     184             :       requires: complex double
     185             :       filter: sed -e "s/46483/46484/" | sed -e "s/54946/54945/" | sed -e "s/48456/48457/" | sed -e "s/74117/74116/" | sed -e "s/37240/37241/"
     186             :       output_file: output/butterfly_4.out
     187             :       test:
     188             :          suffix: 4
     189             :       test:
     190             :          suffix: 4_hankel
     191             :          args: -pep_ciss_extraction hankel
     192             : 
     193             : TEST*/

Generated by: LCOV version 1.14