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 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
|
/*
ARPACK++ v1.0 8/1/1997
c++ interface to ARPACK code.
MODULE CMatrixB.h
Class template for the tridiagonal matrix derived from
the standard central difference of the 1-d convection diffusion
operator u" + rho*u' on the interval [0, 1] with zero
Dirichlet boundary conditions.
ARPACK Authors
Richard Lehoucq
Danny Sorensen
Chao Yang
Dept. of Computational & Applied Mathematics
Rice University
Houston, Texas
*/
#ifndef CMATRIXB_H
#define CMATRIXB_H
#include "arcomp.h"
#include "matprod.h"
#include "blas1c.h"
#include "lapackc.h"
template<class T>
class CompMatrixB: public MatrixWithProduct<arcomplex<T> > {
private:
arcomplex<T> rho;
arcomplex<T> shift;
arcomplex<T> *Ad, *Adl, *Adu, *Adu2;
int *ipiv;
int decsize;
void FactorDataDeallocate();
public:
void FactorOP();
void MultMv(arcomplex<T>* v, arcomplex<T>* w);
void MultOPv(arcomplex<T>* v, arcomplex<T>* w);
CompMatrixB(int nv, arcomplex<T> rhov);
CompMatrixB(int nv, arcomplex<T> shiftv, arcomplex<T> rhov);
virtual ~CompMatrixB();
}; // CompMatrixB.
template<class T>
inline void CompMatrixB<T>::FactorDataDeallocate()
/*
Eliminates the data structure used on matrix factorization.
*/
{
delete[] Ad;
delete[] Adl;
delete[] Adu;
delete[] Adu2;
delete[] ipiv;
} // FactorDataDeallocate.
template<class T>
void CompMatrixB<T>::FactorOP()
/*
Factors (M-shift*I).
*/
{
int j, ierr;
arcomplex<T> h, h2, s, s1, s2, s3;
const arcomplex<T> one(1.0, 0.0);
const arcomplex<T> two(2.0, 0.0);
if (decsize != this->ncols()) {
decsize = this->ncols();
FactorDataDeallocate();
Ad = new arcomplex<T>[this->ncols()];
Adl = new arcomplex<T>[this->ncols()];
Adu = new arcomplex<T>[this->ncols()];
Adu2 = new arcomplex<T>[this->ncols()];
ipiv = new int[this->ncols()];
}
h = one/arcomplex<T>((this->ncols()+1),0.0);
h2 = h*h;
s = rho/two;
s1 = -one/h2 - s/h;
s2 = two/h2 - shift;
s3 = -one/h2 + s/h;
for (j=0; j<this->ncols()-1; j++) {
Adl[j] = s1;
Ad[j] = s2;
Adu[j] = s3;
}
Ad[this->ncols()-1] = s2;
gttrf(this->ncols(), Adl, Ad, Adu, Adu2, ipiv, ierr);
} // FactorOP.
template<class T>
void CompMatrixB<T>::MultMv(arcomplex<T>* v, arcomplex<T>* w)
/*
Computes the matrix-vector multiplication w <- A*v.
*/
{
int j;
arcomplex<T> dd, dl, du, s, h, h2;
const arcomplex<T> one( 1.0, 0.0);
const arcomplex<T> two( 2.0, 0.0);
h = one/arcomplex<T>((this->ncols()+1),0.0);
h2 = h*h;
s = rho/two;
dd = two/h2;
dl = -one/h2 - s/h;
du = -one/h2 + s/h;
w[0] = dd*v[0] + du*v[1];
for (j=1; j<this->ncols()-1; j++) {
w[j] = dl*v[j-1] + dd*v[j] + du*v[j+1];
}
w[this->ncols()-1] = dl*v[this->ncols()-2] + dd*v[this->ncols()-1];
} // MultMv.
template<class T>
void CompMatrixB<T>::MultOPv(arcomplex<T>* v, arcomplex<T>* w)
/*
Computes the matrix-vector product w <- inv(M-shift*I)*v.
*/
{
int ierr;
char *type = "N";
copy(this->ncols(), v, 1, w, 1);
gttrs(type, this->ncols(), 1, Adl, Ad, Adu, Adu2, ipiv, w, this->ncols(), ierr);
} // MultOPv.
template<class T>
inline CompMatrixB<T>::CompMatrixB(int nval, arcomplex<T> rhov):
MatrixWithProduct<arcomplex<T> >(nval)
/*
Constructor
*/
{
decsize = 0;
Ad = 0;
Adl = 0;
Adu = 0;
Adu2 = 0;
ipiv = 0;
shift = 0.0;
rho = rhov;
} // Constructor.
template<class T>
inline CompMatrixB<T>::
CompMatrixB(int nv, arcomplex<T> shiftv, arcomplex<T> rhov):
MatrixWithProduct<arcomplex<T> >(nv)
/*
Constructor with shift
*/
{
decsize = 0;
Ad = 0;
Adl = 0;
Adu = 0;
Adu2 = 0;
ipiv = 0;
shift = shiftv;
rho = rhov;
FactorOP();
} // Constructor with shift.
template<class T>
inline CompMatrixB<T>::~CompMatrixB()
/*
Destructor
*/
{
FactorDataDeallocate();
} // Destructor.
#endif // CMATRIXB_H
|