1 /*
2 ARPACK++ v1.2 2/18/2000
3 c++ interface to ARPACK code.
4
5 MODULE ACompShf.cc
6 Example program that illustrates how to solve a complex standard
7 eigenvalue problem in shift and invert mode using the AREig function.
8
9 1) Problem description:
10
11 In this example we try to solve A*x = x*lambda in shift and invert
12 mode, where A is derived from the central difference discretization
13 of the 1-dimensional convection-diffusion operator
14 (d^2u/dx^2) + rho*(du/dx)
15 on the interval [0,1] with zero Dirichlet boundary conditions.
16
17 2) Data structure used to represent matrix A:
18
19 {nnzA, irowA, pcolA, valA}: matrix A data in CSC format.
20
21 3) Library called by this example:
22
23 The SuperLU package is called by AREig to solve some linear
24 systems involving (A-sigma*I). This is needed to implement
25 the shift and invert strategy.
26
27 4) Included header files:
28
29 File Contents
30 ----------- ---------------------------------------------
31 lcmatrxb.h CompMatricB, a function that generates matrix
32 A in CSC format.
33 areig.h The AREig function definition.
34 acompsol.h The Solution function.
35 arcomp.h The "arcomplex" (complex) type definition.
36
37 5) ARPACK Authors:
38
39 Richard Lehoucq
40 Kristyn Maschhoff
41 Danny Sorensen
42 Chao Yang
43 Dept. of Computational & Applied Mathematics
44 Rice University
45 Houston, Texas
46 */
47
48 #include "arcomp.h"
49 #include "lcmatrxb.h"
50 #include "areig.h"
51 #include "acompsol.h"
52
main()53 int main()
54 {
55
56 // Defining variables;
57
58 int n; // Dimension of the problem.
59 int nnz; // Number of nonzero elements in A.
60 int nconv; // Number of "converged" eigenvalues.
61 int* irow; // pointer to an array that stores the row
62 // indices of the nonzeros in A.
63 int* pcol; // pointer to an array of pointers to the
64 // beginning of each column in vector A.
65 arcomplex<double> rho; // Parameter used by CompMatrixB.
66 arcomplex<double> *A; // pointer to an array that stores the
67 // nonzero elements of A.
68 arcomplex<double> EigVal[101]; // Eigenvalues.
69 arcomplex<double> EigVec[1001]; // Eigenvectors stored sequentially.
70
71 // Creating a complex matrix.
72
73 n = 100;
74 rho = 10.0;
75 CompMatrixB(n, rho, nnz, A, irow, pcol);
76
77 // Finding the four eigenvalues of A nearest to 0.0 and the
78 // related eigenvectors.
79
80 nconv = AREig(EigVal, EigVec, n, nnz, A, irow, pcol,
81 arcomplex<double>(0.0, 0.0), 4L);
82
83 // Printing solution.
84
85 Solution(nconv, n, nnz, A, irow, pcol, EigVal, EigVec);
86
87 } // main.
88