1: /*
2: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3: SLEPc - Scalable Library for Eigenvalue Problem Computations
4: Copyright (c) 2002-2014, Universitat Politecnica de Valencia, Spain
6: This file is part of SLEPc.
8: SLEPc is free software: you can redistribute it and/or modify it under the
9: terms of version 3 of the GNU Lesser General Public License as published by
10: the Free Software Foundation.
12: SLEPc is distributed in the hope that it will be useful, but WITHOUT ANY
13: WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14: FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
15: more details.
17: You should have received a copy of the GNU Lesser General Public License
18: along with SLEPc. If not, see <http://www.gnu.org/licenses/>.
19: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
20: */
22: static char help[] = "Test matrix exponential in DSHEP.\n\n";
24: #include <slepcds.h>
28: int main(int argc,char **argv) 29: {
31: DS ds;
32: PetscScalar *A;
33: PetscInt i,j,n=10,ld;
34: PetscViewer viewer;
35: PetscBool verbose;
37: SlepcInitialize(&argc,&argv,(char*)0,help);
38: PetscOptionsGetInt(NULL,"-n",&n,NULL);
39: PetscPrintf(PETSC_COMM_WORLD,"Compute symmetric matrix exponential - dimension %D.\n",n);
40: PetscOptionsHasName(NULL,"-verbose",&verbose);
42: /* Create DS object */
43: DSCreate(PETSC_COMM_WORLD,&ds);
44: DSSetType(ds,DSHEP);
45: DSSetFromOptions(ds);
46: ld = n+2; /* test leading dimension larger than n */
47: DSAllocate(ds,ld);
48: DSSetDimensions(ds,n,0,0,0);
50: /* Set up viewer */
51: PetscViewerASCIIGetStdout(PETSC_COMM_WORLD,&viewer);
52: PetscViewerPushFormat(viewer,PETSC_VIEWER_ASCII_INFO_DETAIL);
53: DSView(ds,viewer);
54: PetscViewerPopFormat(viewer);
55: if (verbose) {
56: PetscViewerPushFormat(viewer,PETSC_VIEWER_ASCII_MATLAB);
57: }
59: /* Fill with a symmetric Toeplitz matrix */
60: DSGetArray(ds,DS_MAT_A,&A);
61: for (i=0;i<n;i++) A[i+i*ld]=2.0;
62: for (j=1;j<3;j++) {
63: for (i=0;i<n-j;i++) { A[i+(i+j)*ld]=1.0; A[(i+j)+i*ld]=1.0; }
64: }
65: DSRestoreArray(ds,DS_MAT_A,&A);
66: DSSetState(ds,DS_STATE_RAW);
67: if (verbose) {
68: PetscPrintf(PETSC_COMM_WORLD,"Matrix A - - - - - - - -\n");
69: DSView(ds,viewer);
70: }
72: /* Compute matrix exponential */
73: DSComputeFunction(ds,SLEPC_FUNCTION_EXP);
74: if (verbose) {
75: PetscPrintf(PETSC_COMM_WORLD,"Computed f(A) - - - - - - -\n");
76: DSViewMat(ds,viewer,DS_MAT_F);
77: }
79: DSDestroy(&ds);
80: SlepcFinalize();
81: return 0;
82: }