LCOV - code coverage report
Current view: top level - eps/tutorials - ex2.c (source / functions) Hit Total Coverage
Test: SLEPc Lines: 46 50 92.0 %
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             : static char help[] = "Standard symmetric eigenproblem corresponding to the Laplacian operator in 2 dimensions.\n\n"
      12             :   "The command line options are:\n"
      13             :   "  -n <n>, where <n> = number of grid subdivisions in x dimension.\n"
      14             :   "  -m <m>, where <m> = number of grid subdivisions in y dimension.\n\n";
      15             : 
      16             : #include <slepceps.h>
      17             : 
      18          17 : int main(int argc,char **argv)
      19             : {
      20          17 :   Mat            A;               /* operator matrix */
      21          17 :   EPS            eps;             /* eigenproblem solver context */
      22          17 :   EPSType        type;
      23          17 :   EPSStop        stop;
      24          17 :   PetscReal      thres;
      25          17 :   PetscInt       N,n=10,m,Istart,Iend,II,nev,i,j;
      26          17 :   PetscBool      flag,terse;
      27             : 
      28          17 :   PetscFunctionBeginUser;
      29          17 :   PetscCall(SlepcInitialize(&argc,&argv,NULL,help));
      30             : 
      31          17 :   PetscCall(PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL));
      32          17 :   PetscCall(PetscOptionsGetInt(NULL,NULL,"-m",&m,&flag));
      33          17 :   if (!flag) m=n;
      34          17 :   N = n*m;
      35          17 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD,"\n2-D Laplacian Eigenproblem, N=%" PetscInt_FMT " (%" PetscInt_FMT "x%" PetscInt_FMT " grid)\n\n",N,n,m));
      36             : 
      37             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      38             :      Compute the operator matrix that defines the eigensystem, Ax=kx
      39             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
      40             : 
      41          17 :   PetscCall(MatCreate(PETSC_COMM_WORLD,&A));
      42          17 :   PetscCall(MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,N,N));
      43          17 :   PetscCall(MatSetFromOptions(A));
      44             : 
      45          17 :   PetscCall(MatGetOwnershipRange(A,&Istart,&Iend));
      46       24395 :   for (II=Istart;II<Iend;II++) {
      47       24378 :     i = II/n; j = II-i*n;
      48       24378 :     if (i>0) PetscCall(MatSetValue(A,II,II-n,-1.0,INSERT_VALUES));
      49       24378 :     if (i<m-1) PetscCall(MatSetValue(A,II,II+n,-1.0,INSERT_VALUES));
      50       24378 :     if (j>0) PetscCall(MatSetValue(A,II,II-1,-1.0,INSERT_VALUES));
      51       24378 :     if (j<n-1) PetscCall(MatSetValue(A,II,II+1,-1.0,INSERT_VALUES));
      52       24378 :     PetscCall(MatSetValue(A,II,II,4.0,INSERT_VALUES));
      53             :   }
      54             : 
      55          17 :   PetscCall(MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY));
      56          17 :   PetscCall(MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY));
      57             : 
      58             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      59             :                 Create the eigensolver and set various options
      60             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
      61             : 
      62             :   /*
      63             :      Create eigensolver context
      64             :   */
      65          17 :   PetscCall(EPSCreate(PETSC_COMM_WORLD,&eps));
      66             : 
      67             :   /*
      68             :      Set operators. In this case, it is a standard eigenvalue problem
      69             :   */
      70          17 :   PetscCall(EPSSetOperators(eps,A,NULL));
      71          17 :   PetscCall(EPSSetProblemType(eps,EPS_HEP));
      72             : 
      73             :   /*
      74             :      Set solver parameters at runtime
      75             :   */
      76          17 :   PetscCall(EPSSetFromOptions(eps));
      77             : 
      78             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      79             :                       Solve the eigensystem
      80             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
      81             : 
      82          17 :   PetscCall(EPSSolve(eps));
      83             : 
      84             :   /*
      85             :      Optional: Get some information from the solver and display it
      86             :   */
      87          17 :   PetscCall(EPSGetType(eps,&type));
      88          17 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD," Solution method: %s\n\n",type));
      89          17 :   PetscCall(EPSGetStoppingTest(eps,&stop));
      90          17 :   if (stop!=EPS_STOP_THRESHOLD) {
      91          13 :     PetscCall(EPSGetDimensions(eps,&nev,NULL,NULL));
      92          13 :     PetscCall(PetscPrintf(PETSC_COMM_WORLD," Number of requested eigenvalues: %" PetscInt_FMT "\n",nev));
      93             :   } else {
      94           4 :     PetscCall(EPSGetThreshold(eps,&thres,NULL));
      95           4 :     PetscCall(PetscPrintf(PETSC_COMM_WORLD," Using threshold: %.4g\n",(double)thres));
      96             :   }
      97             : 
      98             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      99             :                     Display solution and clean up
     100             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     101             : 
     102             :   /* show detailed info unless -terse option is given by user */
     103          17 :   PetscCall(PetscOptionsHasName(NULL,NULL,"-terse",&terse));
     104          17 :   if (terse) PetscCall(EPSErrorView(eps,EPS_ERROR_RELATIVE,NULL));
     105             :   else {
     106           0 :     PetscCall(PetscViewerPushFormat(PETSC_VIEWER_STDOUT_WORLD,PETSC_VIEWER_ASCII_INFO_DETAIL));
     107           0 :     PetscCall(EPSConvergedReasonView(eps,PETSC_VIEWER_STDOUT_WORLD));
     108           0 :     PetscCall(EPSErrorView(eps,EPS_ERROR_RELATIVE,PETSC_VIEWER_STDOUT_WORLD));
     109           0 :     PetscCall(PetscViewerPopFormat(PETSC_VIEWER_STDOUT_WORLD));
     110             :   }
     111          17 :   PetscCall(EPSDestroy(&eps));
     112          17 :   PetscCall(MatDestroy(&A));
     113          17 :   PetscCall(SlepcFinalize());
     114             :   return 0;
     115             : }
     116             : 
     117             : /*TEST
     118             : 
     119             :    testset:
     120             :       args: -n 72 -eps_nev 4 -eps_ncv 20 -terse
     121             :       output_file: output/ex2_1.out
     122             :       requires: !single
     123             :       test:
     124             :          suffix: 1
     125             :       test:
     126             :          suffix: 2
     127             :          requires: defined(PETSC_HAVE_DYNAMIC_LIBRARIES) defined(PETSC_USE_SHARED_LIBRARIES)
     128             :          args: -library_preload
     129             : 
     130             :    testset:
     131             :       args: -n 30 -eps_type ciss -eps_ciss_realmats -terse
     132             :       requires: !single
     133             :       output_file: output/ex2_ciss.out
     134             :       filter: grep -v method
     135             :       test:
     136             :          suffix: ciss_1
     137             :          nsize: 1
     138             :          args: -rg_type interval -rg_interval_endpoints 1.1,1.25,-.1,.1
     139             :          requires: complex
     140             :       test:
     141             :          suffix: ciss_1_hpddm
     142             :          nsize: 1
     143             :          args: -rg_type interval -rg_interval_endpoints 1.1,1.25 -st_ksp_type hpddm
     144             :          requires: hpddm
     145             :       test:
     146             :          suffix: ciss_2
     147             :          nsize: 2
     148             :          args: -rg_type ellipse -rg_ellipse_center 1.175 -rg_ellipse_radius 0.075 -eps_ciss_partitions 2
     149             :       test:
     150             :          suffix: ciss_2_block
     151             :          args: -rg_type ellipse -rg_ellipse_center 1.175 -rg_ellipse_radius 0.075 -eps_ciss_blocksize 3 -eps_ciss_moments 2
     152             :          requires: complex !__float128
     153             :       test:
     154             :          suffix: ciss_2_hpddm
     155             :          nsize: 2
     156             :          args: -rg_type ellipse -rg_ellipse_center 1.175 -rg_ellipse_radius 0.075 -eps_ciss_partitions 2 -eps_ciss_ksp_type hpddm
     157             :          requires: hpddm
     158             :       test:
     159             :          suffix: feast
     160             :          args: -eps_type feast -eps_interval 1.1,1.25 -eps_ncv 64 -options_left 0
     161             :          requires: feast
     162             : 
     163             :    testset:
     164             :       args: -n 30 -m 30 -eps_interval 3.9,4.15 -terse
     165             :       output_file: output/ex2_3.out
     166             :       filter: grep -v Solution
     167             :       requires: !single
     168             :       test:
     169             :          suffix: 3
     170             :          args: -st_type sinvert -st_pc_type cholesky
     171             :       test:
     172             :          suffix: 3_evsl
     173             :          args: -eps_type evsl -eps_evsl_slices 6
     174             :          requires: evsl
     175             : 
     176             :    testset:
     177             :       args: -n 45 -m 46 -eps_interval 4.54,4.57 -eps_ncv 24 -terse
     178             :       output_file: output/ex2_4.out
     179             :       filter: grep -v Solution
     180             :       requires: !single
     181             :       timeoutfactor: 2
     182             :       test:
     183             :          suffix: 4
     184             :          args: -st_type sinvert -st_pc_type cholesky
     185             :       test:
     186             :          suffix: 4_filter
     187             :          args: -eps_type {{krylovschur subspace}} -st_type filter -st_filter_degree 200
     188             :          requires: !__float128
     189             :       test:
     190             :          suffix: 4_filter_cuda
     191             :          args: -eps_type {{krylovschur subspace}} -st_type filter -st_filter_degree 200 -mat_type aijcusparse
     192             :          requires: cuda
     193             :       test:
     194             :          suffix: 4_filter_hip
     195             :          args: -eps_type {{krylovschur subspace}} -st_type filter -st_filter_degree 200 -mat_type aijhipsparse
     196             :          requires: hip
     197             :       test:
     198             :          suffix: 4_evsl
     199             :          args: -eps_type evsl
     200             :          requires: evsl
     201             : 
     202             :    test:
     203             :       args: -n 25 -m 24 -eps_threshold_absolute .25 -eps_smallest_magnitude -eps_ncv 10 -terse
     204             :       suffix: 5
     205             :       requires: !single
     206             : 
     207             :    testset:
     208             :       args: -n 25 -m 24 -st_type sinvert -terse
     209             :       requires: double
     210             :       test:
     211             :          suffix: 6
     212             :          args: -eps_threshold_absolute .15 -eps_target 0.01
     213             :       test:
     214             :          suffix: 6_rel_large
     215             :          args: -eps_threshold_relative .98 -eps_target 8
     216             :       test:
     217             :          suffix: 6_rel_small
     218             :          args: -eps_threshold_relative 3
     219             : 
     220             : TEST*/

Generated by: LCOV version 1.14