File: cgenprbb.h

package info (click to toggle)
arpack%2B%2B 2.3-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 4,548 kB
  • ctags: 3,751
  • sloc: cpp: 16,612; sh: 8,819; ansic: 2,312; makefile: 257
file content (163 lines) | stat: -rw-r--r-- 3,132 bytes parent folder | download | duplicates (9)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
   ARPACK++ v1.0 8/1/1997
   c++ interface to ARPACK code.

   MODULE CGenPrbB.h
   Very simple template class intended to illustrate how to
   use ARPACK++ to find some few eigenvalues and eigenvectors
   of complex generalized problems in shift and invert mode.

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

#ifndef CGENPRBB_H
#define CGENPRBB_H

#include "arcomp.h"
#include "blas1c.h"
#include "lapackc.h"
#include "cmatrixe.h"
#include "cmatrixf.h"


template <class T>
class ComplexGenProblemB {

 private:

  int          n, decsize;
  int          *ipiv;
  arcomplex<T> rho;
  arcomplex<T> shift;
  arcomplex<T> *Ad, *Adl, *Adu, *Adu2;

  void FactorDataDeallocate();
  // Eliminates the data structure used on matrix factorization.

  void FactorOP();
  // Factors (A-shift*B).

 public:

  ComplexMatrixE<T> A;
  ComplexMatrixF<T> B;

  void MultAv(arcomplex<T> *v, arcomplex<T> *w) { A.MultMv(v,w); }
  // Performs the matrix-vector multiplication w <- A*v.

  void MultBv(arcomplex<T> *v, arcomplex<T> *w) { B.MultMv(v,w); }
  // Performs the matrix-vector multiplication w <- B*v.

  void MultOPv(arcomplex<T>* v, arcomplex<T>* w);
  // Performs the matrix-vector multiplication w <- inv(A-shift*B)*v.

  ComplexGenProblemB(int nx, arcomplex<T> rhop, arcomplex<T> shiftp);
  // Constructor.

  ~ComplexGenProblemB();
  // Destructor

}; // struct ComplexGenProblemA.


template<class T>
inline void ComplexGenProblemB<T>::FactorDataDeallocate()
{

  delete[] Ad;
  delete[] Adl;
  delete[] Adu;
  delete[] Adu2;
  delete[] ipiv;

} // FactorDataDeallocate.


template<class T>
void ComplexGenProblemB<T>::FactorOP()
{

  int          j, ierr;
  arcomplex<T> h, s, s1, s2, s3;

  const arcomplex<T> one(1.0, 0.0);
  const arcomplex<T> two(2.0, 0.0);
  const arcomplex<T> four(4.0, 0.0);

  if (decsize != n) {
    decsize = n;
    FactorDataDeallocate();
    Ad   = new arcomplex<T>[n];
    Adl  = new arcomplex<T>[n];
    Adu  = new arcomplex<T>[n];
    Adu2 = new arcomplex<T>[n];
    ipiv = new int[n];
  }

  h  = one/arcomplex<T>((n+1),0.0);
  s  = rho/two;
  s1 = -one/h - s - shift*h;
  s2 = two/h - four*shift*h;
  s3 = -one/h + s - shift*h;

  for (j=0; j<n-1; j++) {
    Adl[j] = s1;
    Ad[j]  = s2;
    Adu[j] = s3;
  }
  Ad[n-1]  = s2;

  gttrf(n, Adl, Ad, Adu, Adu2, ipiv, ierr);

} // FactorOP.


template<class T>
void ComplexGenProblemB<T>::MultOPv(arcomplex<T>* v, arcomplex<T>* w)
{

  int  ierr;
  char *type = "N";

  copy(n, v, 1, w, 1);
  gttrs(type, n, 1, Adl, Ad, Adu, Adu2, ipiv, w, n, ierr);

} // MultOPv.


template<class T>
ComplexGenProblemB<T>::
ComplexGenProblemB(int nx, arcomplex<T> rhop, arcomplex<T> shiftp): A(nx,rhop), B(nx)
{

  rho     = rhop;
  shift   = shiftp;
  decsize = 0;
  Ad      = 0;
  Adl     = 0;
  Adu     = 0;
  Adu2    = 0;
  ipiv    = 0;
  n       = A.ncols();
  FactorOP();

} // Constructor.


template<class T>
ComplexGenProblemB<T>::~ComplexGenProblemB()
{

  FactorDataDeallocate();

} // Destructor.


#endif // CGENPRBB_H