Actual source code: test16.c
slepc-3.18.2 2023-01-26
1: /*
2: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3: SLEPc - Scalable Library for Eigenvalue Problem Computations
4: Copyright (c) 2002-, Universitat Politecnica de Valencia, Spain
6: This file is part of SLEPc.
7: SLEPc is distributed under a 2-clause BSD license (see LICENSE).
8: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
9: */
11: static char help[] = "Test pseudo-orthogonalization.\n\n";
13: #include <slepcds.h>
15: int main(int argc,char **argv)
16: {
17: DS ds;
18: PetscReal *s,*ns;
19: PetscScalar *A;
20: PetscInt i,j,n=10;
21: PetscViewer viewer;
22: PetscBool verbose;
25: SlepcInitialize(&argc,&argv,(char*)0,help);
26: PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL);
27: PetscPrintf(PETSC_COMM_WORLD,"Test pseudo-orthogonalization for GHIEP - dimension %" PetscInt_FMT ".\n",n);
28: PetscOptionsHasName(NULL,NULL,"-verbose",&verbose);
30: /* Create DS object */
31: DSCreate(PETSC_COMM_WORLD,&ds);
32: DSSetType(ds,DSGHIEP);
33: DSSetFromOptions(ds);
34: DSAllocate(ds,n);
35: DSSetDimensions(ds,n,0,0);
37: /* Set up viewer */
38: PetscViewerASCIIGetStdout(PETSC_COMM_WORLD,&viewer);
39: if (verbose) PetscViewerPushFormat(viewer,PETSC_VIEWER_ASCII_MATLAB);
41: /* Fill with a symmetric Toeplitz matrix */
42: DSGetArray(ds,DS_MAT_A,&A);
43: for (i=0;i<n;i++) A[i+i*n]=2.0;
44: for (j=1;j<3;j++) {
45: for (i=0;i<n-j;i++) { A[i+(i+j)*n]=1.0; A[(i+j)+i*n]=1.0; }
46: }
47: for (j=1;j<3;j++) { A[0+j*n]=-1.0*(j+2); A[j+0*n]=-1.0*(j+2); }
48: DSRestoreArray(ds,DS_MAT_A,&A);
49: DSSetState(ds,DS_STATE_RAW);
50: if (verbose) {
51: PetscPrintf(PETSC_COMM_WORLD,"Initial - - - - - - - - -\n");
52: DSView(ds,viewer);
53: }
55: /* Signature matrix */
56: PetscMalloc2(n,&s,n,&ns);
57: s[0] = -1.0;
58: for (i=1;i<n-1;i++) s[i]=1.0;
59: s[n-1] = -1.0;
61: /* Orthogonalize and show signature */
62: DSPseudoOrthogonalize(ds,DS_MAT_A,n,s,NULL,ns);
63: if (verbose) {
64: PetscPrintf(PETSC_COMM_WORLD,"After pseudo-orthogonalize - - - - - - - - -\n");
65: DSView(ds,viewer);
66: }
67: PetscPrintf(PETSC_COMM_WORLD,"Resulting signature:\n");
68: for (i=0;i<n;i++) PetscPrintf(PETSC_COMM_WORLD,"%g\n",(double)ns[i]);
69: PetscFree2(s,ns);
71: DSDestroy(&ds);
72: SlepcFinalize();
73: return 0;
74: }
76: /*TEST
78: test:
79: suffix: 1
81: TEST*/