LCOV - code coverage report
Current view: top level - eps/tests - test32.c (source / functions) Hit Total Coverage
Test: SLEPc Lines: 57 57 100.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[] = "Tests a GHEP problem with symmetric matrices.\n\n";
      12             : 
      13             : #include <slepceps.h>
      14             : 
      15          25 : int main(int argc,char **argv)
      16             : {
      17          25 :   Mat            A,B;        /* matrices */
      18          25 :   EPS            eps;        /* eigenproblem solver context */
      19          25 :   ST             st;
      20          25 :   KSP            ksp;
      21          25 :   PC             pc;
      22          25 :   PCType         pctype;
      23          25 :   PetscInt       N,n=45,m,Istart,Iend,II,i,j;
      24          25 :   PetscBool      flag;
      25             : 
      26          25 :   PetscFunctionBeginUser;
      27          25 :   PetscCall(SlepcInitialize(&argc,&argv,NULL,help));
      28          25 :   PetscCall(PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL));
      29          25 :   PetscCall(PetscOptionsGetInt(NULL,NULL,"-m",&m,&flag));
      30          25 :   if (!flag) m=n;
      31          25 :   N = n*m;
      32          25 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD,"\nGeneralized Symmetric Eigenproblem, N=%" PetscInt_FMT " (%" PetscInt_FMT "x%" PetscInt_FMT " grid)\n\n",N,n,m));
      33             : 
      34             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      35             :      Compute the matrices that define the eigensystem, Ax=kBx
      36             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
      37             : 
      38          25 :   PetscCall(MatCreate(PETSC_COMM_WORLD,&A));
      39          25 :   PetscCall(MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,N,N));
      40          25 :   PetscCall(MatSetFromOptions(A));
      41             : 
      42          25 :   PetscCall(MatCreate(PETSC_COMM_WORLD,&B));
      43          25 :   PetscCall(MatSetSizes(B,PETSC_DECIDE,PETSC_DECIDE,N,N));
      44          25 :   PetscCall(MatSetFromOptions(B));
      45             : 
      46          25 :   PetscCall(MatGetOwnershipRange(A,&Istart,&Iend));
      47        3210 :   for (II=Istart;II<Iend;II++) {
      48        3185 :     i = II/n; j = II-i*n;
      49        3185 :     if (i>0) PetscCall(MatSetValue(A,II,II-n,-1.0,INSERT_VALUES));
      50        3185 :     if (i<m-1) PetscCall(MatSetValue(A,II,II+n,-1.0,INSERT_VALUES));
      51        3185 :     if (j>0) PetscCall(MatSetValue(A,II,II-1,-1.0,INSERT_VALUES));
      52        3185 :     if (j<n-1) PetscCall(MatSetValue(A,II,II+1,-1.0,INSERT_VALUES));
      53        3185 :     PetscCall(MatSetValue(A,II,II,4.0,INSERT_VALUES));
      54        3185 :     PetscCall(MatSetValue(B,II,II,2.0/PetscLogScalar(II+2),INSERT_VALUES));
      55             :   }
      56          25 :   PetscCall(MatSetValue(B,0,1,0.4,INSERT_VALUES));
      57          25 :   PetscCall(MatSetValue(B,1,0,0.4,INSERT_VALUES));
      58             : 
      59          25 :   PetscCall(MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY));
      60          25 :   PetscCall(MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY));
      61          25 :   PetscCall(MatAssemblyBegin(B,MAT_FINAL_ASSEMBLY));
      62          25 :   PetscCall(MatAssemblyEnd(B,MAT_FINAL_ASSEMBLY));
      63             : 
      64          25 :   PetscCall(MatSetOption(A,MAT_SYMMETRIC,PETSC_TRUE));
      65          25 :   PetscCall(MatSetOption(A,MAT_HERMITIAN,PETSC_TRUE));
      66          25 :   PetscCall(MatSetOption(B,MAT_SYMMETRIC,PETSC_TRUE));
      67          25 :   PetscCall(MatSetOption(B,MAT_HERMITIAN,PETSC_TRUE));
      68             : 
      69             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      70             :                 Create the eigensolver and solve the problem
      71             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
      72             : 
      73          25 :   PetscCall(EPSCreate(PETSC_COMM_WORLD,&eps));
      74          25 :   PetscCall(EPSSetOperators(eps,A,B));
      75          25 :   PetscCall(EPSSetProblemType(eps,EPS_GHEP));
      76          25 :   PetscCall(EPSSetFromOptions(eps));
      77          25 :   PetscCall(EPSSetUp(eps));
      78          25 :   PetscCall(EPSGetST(eps,&st));
      79          25 :   PetscCall(STGetKSP(st,&ksp));
      80          25 :   PetscCall(KSPGetPC(ksp,&pc));
      81          25 :   PetscCall(PCGetType(pc,&pctype));
      82          25 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD," Using %s for the PC\n",pctype));
      83          25 :   PetscCall(EPSSolve(eps));
      84          25 :   PetscCall(EPSErrorView(eps,EPS_ERROR_BACKWARD,NULL));
      85             : 
      86          25 :   PetscCall(EPSDestroy(&eps));
      87          25 :   PetscCall(MatDestroy(&A));
      88          25 :   PetscCall(MatDestroy(&B));
      89          25 :   PetscCall(SlepcFinalize());
      90             :   return 0;
      91             : }
      92             : 
      93             : /*TEST
      94             : 
      95             :    test:
      96             :       suffix: 1
      97             :       args: -n 18 -eps_nev 3 -st_type sinvert -eps_target 1.02
      98             : 
      99             :    test:
     100             :       suffix: 2
     101             :       args: -n 18 -eps_type ciss -rg_interval_endpoints 1.0,1.2
     102             :       requires: !single
     103             : 
     104             :    testset:
     105             :       nsize: {{1 4}}
     106             :       args: -n 8 -eps_nev 60 -st_pc_type redundant
     107             :       filter: grep -v Using
     108             :       requires: !single
     109             :       output_file: output/test32_3.out
     110             :       test:
     111             :          suffix: 3
     112             :       test:
     113             :          suffix: 3_gnhep
     114             :          args: -eps_gen_non_hermitian
     115             : 
     116             :    testset:
     117             :       nsize: {{1 4}}
     118             :       args: -n 8 -eps_nev 64 -st_pc_type redundant
     119             :       filter: grep -v Using
     120             :       requires: !single
     121             :       output_file: output/test32_4.out
     122             :       test:
     123             :          suffix: 4
     124             :       test:
     125             :          suffix: 4_gnhep
     126             :          args: -eps_gen_non_hermitian
     127             : 
     128             :    testset:
     129             :       requires: !single
     130             :       args: -eps_tol 1e-10 -st_type sinvert -st_ksp_type preonly -st_pc_type cholesky -eps_interval .8,1.1 -eps_krylovschur_partitions 2
     131             :       output_file: output/test32_5.out
     132             :       nsize: 3
     133             :       filter: grep -v Using
     134             :       test:
     135             :          suffix: 5_redundant
     136             :          args: -st_pc_type redundant -st_redundant_pc_type cholesky
     137             :       test:
     138             :          suffix: 5_mumps
     139             :          requires: mumps !complex
     140             :          args: -st_pc_factor_mat_solver_type mumps -st_mat_mumps_icntl_13 1
     141             :       test:
     142             :          suffix: 5_superlu
     143             :          requires: superlu_dist
     144             :          args: -st_pc_factor_mat_solver_type superlu_dist -st_mat_superlu_dist_rowperm NOROWPERM
     145             :          timeoutfactor: 10
     146             : 
     147             : TEST*/

Generated by: LCOV version 1.14