LCOV - code coverage report
Current view: top level - svd/tests - test20.c (source / functions) Hit Total Coverage
Test: SLEPc Lines: 42 42 100.0 %
Date: 2024-05-06 00:30:23 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 setting and getting the signature in HSVD.\n"
      12             :   "Based on ex15.c. The command line options are:\n"
      13             :   "  -n <n>, where <n> = matrix dimension.\n"
      14             :   "  -mu <mu>, where <mu> = subdiagonal value.\n\n";
      15             : 
      16             : #include <slepcsvd.h>
      17             : 
      18           1 : int main(int argc,char **argv)
      19             : {
      20           1 :   Mat            A;               /* operator matrix */
      21           1 :   Vec            omega,v;         /* signature */
      22           1 :   SVD            svd;             /* singular value problem solver context */
      23           1 :   PetscReal      mu=PETSC_SQRT_MACHINE_EPSILON;
      24           1 :   PetscInt       n=50,i,j,Istart,Iend;
      25             : 
      26           1 :   PetscFunctionBeginUser;
      27           1 :   PetscCall(SlepcInitialize(&argc,&argv,(char*)0,help));
      28             : 
      29           1 :   PetscCall(PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL));
      30           1 :   PetscCall(PetscOptionsGetReal(NULL,NULL,"-mu",&mu,NULL));
      31           1 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD,"\nLauchli hyperbolic singular value decomposition, (%" PetscInt_FMT " x %" PetscInt_FMT ") mu=%g\n\n",n+1,n,(double)mu));
      32             : 
      33             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      34             :                    Build Lauchli matrix and signature
      35             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
      36             : 
      37           1 :   PetscCall(MatCreate(PETSC_COMM_WORLD,&A));
      38           1 :   PetscCall(MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,n+1,n));
      39           1 :   PetscCall(MatSetFromOptions(A));
      40             : 
      41           1 :   PetscCall(MatGetOwnershipRange(A,&Istart,&Iend));
      42          52 :   for (i=Istart;i<Iend;i++) {
      43          51 :     if (i == 0) {
      44          51 :       for (j=0;j<n;j++) PetscCall(MatSetValue(A,0,j,1.0,INSERT_VALUES));
      45          51 :     } else PetscCall(MatSetValue(A,i,i-1,mu,INSERT_VALUES));
      46             :   }
      47           1 :   PetscCall(MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY));
      48           1 :   PetscCall(MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY));
      49             : 
      50             :   /* signature omega = [ -1 1 1 ... 1 ] */
      51           1 :   PetscCall(MatCreateVecs(A,NULL,&omega));
      52           1 :   PetscCall(VecSet(omega,1.0));
      53           1 :   PetscCall(VecGetOwnershipRange(omega,&Istart,NULL));
      54           1 :   if (Istart==0) PetscCall(VecSetValue(omega,0,-1.0,INSERT_VALUES));
      55           1 :   PetscCall(VecAssemblyBegin(omega));
      56           1 :   PetscCall(VecAssemblyEnd(omega));
      57             : 
      58             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      59             :           Create the singular value solver and set various options
      60             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
      61             : 
      62           1 :   PetscCall(SVDCreate(PETSC_COMM_WORLD,&svd));
      63           1 :   PetscCall(SVDSetSignature(svd,omega));
      64           1 :   PetscCall(SVDSetOperators(svd,A,NULL));
      65           1 :   PetscCall(SVDSetType(svd,SVDTRLANCZOS));
      66           1 :   PetscCall(SVDSetFromOptions(svd));
      67             : 
      68             :   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      69             :                 Solve the problem and display solution
      70             :      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
      71             : 
      72           1 :   PetscCall(SVDSolve(svd));
      73           1 :   PetscCall(SVDErrorView(svd,SVD_ERROR_RELATIVE,PETSC_VIEWER_STDOUT_WORLD));
      74             : 
      75             :   /* Test getting the signature */
      76           1 :   PetscCall(MatCreateVecs(A,NULL,&v));
      77           1 :   PetscCall(SVDGetSignature(svd,v));
      78           1 :   PetscCall(VecView(v,NULL));
      79             : 
      80             :   /* Free work space */
      81           1 :   PetscCall(SVDDestroy(&svd));
      82           1 :   PetscCall(MatDestroy(&A));
      83           1 :   PetscCall(VecDestroy(&omega));
      84           1 :   PetscCall(VecDestroy(&v));
      85           1 :   PetscCall(SlepcFinalize());
      86             :   return 0;
      87             : }
      88             : 
      89             : /*TEST
      90             : 
      91             :    test:
      92             :       requires: double
      93             :       suffix: 1
      94             : 
      95             : TEST*/

Generated by: LCOV version 1.14