LCOV - code coverage report
Current view: top level - sys/classes/st/tests - test5.c (source / functions) Hit Total Coverage
Test: SLEPc Lines: 89 89 100.0 %
Date: 2024-05-04 00:30:31 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[] = "Test various ST interface functions.\n\n";
      12             : 
      13             : #include <slepceps.h>
      14             : 
      15           6 : int main (int argc,char **argv)
      16             : {
      17           6 :   ST             st;
      18           6 :   KSP            ksp;
      19           6 :   PC             pc;
      20           6 :   Mat            A,mat[1],Op;
      21           6 :   Vec            v,w;
      22           6 :   PetscInt       N,n=4,i,j,II,Istart,Iend;
      23           6 :   PetscScalar    d,val1,val2;
      24           6 :   PetscBool      test_compl=PETSC_FALSE;
      25             : 
      26           6 :   PetscFunctionBeginUser;
      27           6 :   PetscCall(SlepcInitialize(&argc,&argv,(char*)0,help));
      28           6 :   PetscCall(PetscOptionsGetBool(NULL,NULL,"-complex",&test_compl,NULL));
      29           6 :   PetscCall(PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL));
      30           6 :   N = n*n;
      31             : 
      32             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      33             :      Create non-symmetric matrix
      34             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
      35             : 
      36           6 :   PetscCall(MatCreate(PETSC_COMM_WORLD,&A));
      37           6 :   PetscCall(MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,N,N));
      38           6 :   PetscCall(MatSetFromOptions(A));
      39             : 
      40           6 :   PetscCall(MatGetOwnershipRange(A,&Istart,&Iend));
      41             : #if defined(PETSC_USE_COMPLEX)
      42           6 :   val1 = test_compl? PetscCMPLX(1.0,-0.2): 1.0;
      43           6 :   val2 = test_compl? PetscCMPLX(-1.0,0.4): -1.0;
      44             : #else
      45             :   val1 = 1.0;
      46             :   val2 = -1.0;
      47             : #endif
      48         102 :   for (II=Istart;II<Iend;II++) {
      49          96 :     i = II/n; j = II-i*n;
      50          96 :     d = 0.0;
      51          96 :     if (i>0) { PetscCall(MatSetValue(A,II,II-n,val1,INSERT_VALUES)); d=d+1.0; }
      52          96 :     if (i<n-1) { PetscCall(MatSetValue(A,II,II+n,val2,INSERT_VALUES)); d=d+1.0; }
      53          96 :     if (j>0) { PetscCall(MatSetValue(A,II,II-1,val1,INSERT_VALUES)); d=d+1.0; }
      54          96 :     if (j<n-1) { PetscCall(MatSetValue(A,II,II+1,val2,INSERT_VALUES)); d=d+1.0; }
      55          96 :     PetscCall(MatSetValue(A,II,II,d,INSERT_VALUES));
      56             :   }
      57           6 :   PetscCall(MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY));
      58           6 :   PetscCall(MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY));
      59             : 
      60             : #if defined(PETSC_USE_COMPLEX)
      61           6 :   val1 = test_compl? PetscCMPLX(-0.5,0.01): -0.5;
      62             : #else
      63             :   val1 = -0.5;
      64             : #endif
      65           6 :   PetscCall(MatCreateVecs(A,&v,&w));
      66           6 :   PetscCall(VecSetValue(v,0,val1,INSERT_VALUES));
      67           6 :   PetscCall(VecSetValue(v,1,1.5,INSERT_VALUES));
      68           6 :   PetscCall(VecSetValue(v,2,2,INSERT_VALUES));
      69           6 :   PetscCall(VecAssemblyBegin(v));
      70           6 :   PetscCall(VecAssemblyEnd(v));
      71           6 :   PetscCall(VecView(v,NULL));
      72             : 
      73             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      74             :      Create the spectral transformation object
      75             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
      76           6 :   PetscCall(STCreate(PETSC_COMM_WORLD,&st));
      77           6 :   mat[0] = A;
      78           6 :   PetscCall(STSetMatrices(st,1,mat));
      79           6 :   PetscCall(STSetType(st,STCAYLEY));
      80           6 :   PetscCall(STSetShift(st,2.0));
      81           6 :   PetscCall(STCayleySetAntishift(st,1.0));
      82           6 :   PetscCall(STSetTransform(st,PETSC_TRUE));
      83             : 
      84           6 :   PetscCall(KSPCreate(PETSC_COMM_WORLD,&ksp));
      85           6 :   PetscCall(KSPSetType(ksp,KSPPREONLY));
      86           6 :   PetscCall(KSPGetPC(ksp,&pc));
      87           6 :   PetscCall(PCSetType(pc,PCLU));
      88           6 :   PetscCall(KSPSetTolerances(ksp,100*PETSC_MACHINE_EPSILON,PETSC_DEFAULT,PETSC_DEFAULT,PETSC_DEFAULT));
      89           6 :   PetscCall(KSPSetFromOptions(ksp));
      90           6 :   PetscCall(STSetKSP(st,ksp));
      91           6 :   PetscCall(KSPDestroy(&ksp));
      92             : 
      93           6 :   PetscCall(STSetFromOptions(st));
      94             : 
      95             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      96             :      Apply the operator
      97             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
      98           6 :   PetscCall(STApply(st,v,w));
      99           6 :   PetscCall(VecView(w,NULL));
     100             : 
     101           6 :   PetscCall(STApplyTranspose(st,v,w));
     102           6 :   PetscCall(VecView(w,NULL));
     103             : 
     104           6 :   if (test_compl) {
     105           3 :     PetscCall(STApplyHermitianTranspose(st,v,w));
     106           3 :     PetscCall(VecView(w,NULL));
     107             :   }
     108             : 
     109           6 :   PetscCall(STMatMult(st,1,v,w));
     110           6 :   PetscCall(VecView(w,NULL));
     111             : 
     112           6 :   PetscCall(STMatMultTranspose(st,1,v,w));
     113           6 :   PetscCall(VecView(w,NULL));
     114             : 
     115           6 :   if (test_compl) {
     116           3 :     PetscCall(STMatMultHermitianTranspose(st,1,v,w));
     117           3 :     PetscCall(VecView(w,NULL));
     118             :   }
     119             : 
     120           6 :   PetscCall(STMatSolve(st,v,w));
     121           6 :   PetscCall(VecView(w,NULL));
     122             : 
     123           6 :   PetscCall(STMatSolveTranspose(st,v,w));
     124           6 :   PetscCall(VecView(w,NULL));
     125             : 
     126           6 :   if (test_compl) {
     127           3 :     PetscCall(STMatSolveHermitianTranspose(st,v,w));
     128           3 :     PetscCall(VecView(w,NULL));
     129             :   }
     130             : 
     131             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     132             :      Get the operator matrix
     133             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     134           6 :   PetscCall(STGetOperator(st,&Op));
     135           6 :   PetscCall(MatMult(Op,v,w));
     136           6 :   PetscCall(VecView(w,NULL));
     137           6 :   PetscCall(MatMultTranspose(Op,v,w));
     138           6 :   PetscCall(VecView(w,NULL));
     139           6 :   if (test_compl) {
     140           3 :     PetscCall(MatMultHermitianTranspose(Op,v,w));
     141           3 :     PetscCall(VecView(w,NULL));
     142             :   }
     143           6 :   PetscCall(STRestoreOperator(st,&Op));
     144             : 
     145           6 :   PetscCall(STDestroy(&st));
     146           6 :   PetscCall(MatDestroy(&A));
     147           6 :   PetscCall(VecDestroy(&v));
     148           6 :   PetscCall(VecDestroy(&w));
     149           6 :   PetscCall(SlepcFinalize());
     150             :   return 0;
     151             : }
     152             : 
     153             : /*TEST
     154             : 
     155             :    testset:
     156             :       output_file: output/test5_1.out
     157             :       requires: !single
     158             :       test:
     159             :          suffix: 1
     160             :          args: -st_matmode {{copy inplace}}
     161             :       test:
     162             :          suffix: 1_shell
     163             :          args: -st_matmode shell -ksp_type bcgs -pc_type jacobi
     164             : 
     165             :    testset:
     166             :       output_file: output/test5_2.out
     167             :       requires: complex !single
     168             :       args: -complex
     169             :       test:
     170             :          suffix: 2
     171             :          args: -st_matmode {{copy inplace}}
     172             :       test:
     173             :          suffix: 2_shell
     174             :          args: -st_matmode shell -ksp_type bcgs -pc_type jacobi
     175             : 
     176             : TEST*/

Generated by: LCOV version 1.14