File: asymgcay.cc

package info (click to toggle)
arpack%2B%2B 2.1-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 4,216 kB
  • ctags: 2,349
  • sloc: cpp: 19,093; ansic: 2,201; makefile: 508
file content (98 lines) | stat: -rw-r--r-- 3,258 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
   ARPACK++ v1.0 8/1/1997
   c++ interface to ARPACK code.

   MODULE ASymGShf.cc.
   Example program that illustrates how to solve a real symmetric
   generalized eigenvalue problem in Cayley mode using the AREig
   function.

   1) Problem description:

      In this example we try to solve A*x = B*x*lambda in Cayley mode,
      where A and B are obtained from the finite element discretization
      of the 1-dimensional discrete Laplacian
                                  d^2u / dx^2
      on the interval [0,1] with zero Dirichlet boundary conditions
      using piecewise linear elements.

   2) Data structure used to represent matrices A and B:

      {nnzA, irowA, pcolA, valA}: upper triangular part of matrix A
                                  stored in CSC format.
      {nnzB, irowB, pcolB, valB}: upper triangular part of matrix B
                                  stored in CSC format.

   3) Library called by this example:

      The SuperLU package is called by AREig to solve some linear
      systems involving (A-sigma*B).

   4) Included header files:

      File             Contents
      -----------      -------------------------------------------
      lsmatrxc.h       SymmetricMatrixC, a function that generates
                       matrix A in CSC format.
      lsmatrxd.h       SymmetricMatrixD, a function that generates
                       matrix B in CSC format.
      areig.h          The AREig function definition.
      asymsol.h        The Solution function.

   5) ARPACK Authors:

      Richard Lehoucq
      Kristyn Maschhoff
      Danny Sorensen
      Chao Yang
      Dept. of Computational & Applied Mathematics
      Rice University
      Houston, Texas
*/

#include "lsmatrxc.h"
#include "lsmatrxd.h"
#include "areig.h"
#include "asymsol.h"


main()
{

  // Defining variables;

  int    n;              // Dimension of the problem.
  int    nconv;          // Number of "converged" eigenvalues.
  int    nnzA,   nnzB;   // Number of nonzero elements in A and B.
  int    *irowA, *irowB; // pointer to an array that stores the row
                         // indices of the nonzeros in A and B.
  int    *pcolA, *pcolB; // pointer to an array of pointers to the
                         // beginning of each column of A (B) in valA (valB).
  double *valA,  *valB;  // pointer to an array that stores the nonzero
                         // elements of A and B.
  double EigVal[101];    // Eigenvalues.
  double EigVec[1001];   // Eigenvectors stored sequentially.
  char   uplo;           // Variable that indicates whether the upper
                         // (uplo='U') ot the lower (uplo='L') part of
                         // A and B will be supplied to AREig.

  // Creating matrices A and B.

  n = 100;
  uplo = 'U';
  SymmetricMatrixC(n, nnzA, valA, irowA, pcolA, uplo);
  SymmetricMatrixD(n, nnzB, valB, irowB, pcolB, uplo);

  // Finding the four eigenvalues of A nearest to 150.0 and the
  // related eigenvectors.

  nconv = AREig(EigVal, EigVec, n, nnzA, valA, irowA, pcolA,
                nnzB, valB, irowB, pcolB, uplo, 'C', 150.0, 4);

  // Printing solution.

  Solution(nconv, n, nnzA, valA, irowA, pcolA, nnzB,
           valB, irowB, pcolB, uplo, EigVal, EigVec);

} // main.