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
|
/*
ARPACK++ v1.0 8/1/1997
c++ interface to ARPACK code.
MODULE CMatrixA.h
Class template for the nx*nx by nx*nx block tridiagonal matrix
| T -I |
|-I T -I |
OP = | -I T |
| ... -I|
| -I T|
derived from the standard central difference discretization
of the 2 dimensional convection-diffusion operator
(Laplacian u) + rho*(du/dx)
on a unit square with zero boundary condition.
T is a nx by nx tridiagonal matrix with DD on the diagonal,
DL on the subdiagonal, and DU on the superdiagonal.
ARPACK Authors
Richard Lehoucq
Danny Sorensen
Chao Yang
Dept. of Computational & Applied Mathematics
Rice University
Houston, Texas
*/
#ifndef CMATRIXA_H
#define CMATRIXA_H
#include "arcomp.h"
#include "blas1c.h"
#include "arcomp.h"
#include "matprod.h"
template<class T>
class CompMatrixA: public MatrixWithProduct<arcomplex<T> > {
private:
int nx;
void MultTv(arcomplex<T>* x, arcomplex<T>* y);
public:
void MultMv(arcomplex<T>* v, arcomplex<T>* w);
CompMatrixA(int nxval);
}; // CompMatrixA.
template<class T>
void CompMatrixA<T>::MultTv(arcomplex<T>* x, arcomplex<T>* y)
/*
Computes the matrix vector multiplication y <- T*x
where T is a nx by nx tridiagonal matrix with DD on the
diagonal, DL on the subdiagonal, and DU on the superdiagonal.
*/
{
int j;
arcomplex<T> h, h2, dd, dl, du;
const arcomplex<T> half(0.5,0.0);
const arcomplex<T> one(1.0,0.0);
const arcomplex<T> four(4.0,0.0);
const arcomplex<T> rho(1.0e2,0.0);
h = one/arcomplex<T>(nx+1,0);
h2 = h*h;
dd = four/h2;
dl = -one/h2 - half*rho/h;
du = -one/h2 + half*rho/h;
y[0] = dd*x[0] + du*x[1];
for (j = 1; j<nx-1; j++) {
y[j] = dl*x[j-1] + dd*x[j] + du*x[j+1];
}
y[nx-1] = dl*x[nx-2] + dd*x[nx-1];
return;
} // MultTv
template<class T>
void CompMatrixA<T>::MultMv(arcomplex<T>* v, arcomplex<T>* w)
/*
Matrix-vector subroutine. Computes w <- M*v.
*/
{
int j, lo;
arcomplex<T> h2;
const arcomplex<T> one(1.0,0.0);
h2 = one/arcomplex<T>((nx+1)*(nx+1),0.0);
MultTv(v,w);
axpy(nx, -one/h2, &v[nx], 1, w, 1);
for (j = 2; j<=nx-1; j++) {
lo = (j-1)*nx;
MultTv(&v[lo], &w[lo]);
axpy(nx, -one/h2, &v[lo-nx], 1, &w[lo], 1);
axpy(nx, -one/h2, &v[lo+nx], 1, &w[lo], 1);
}
lo = (nx-1)*nx;
MultTv(&v[lo], &w[lo]);
axpy(nx, -one/h2, &v[lo-nx], 1, &w[lo], 1);
return;
} // MultMv
template<class T>
CompMatrixA<T>::CompMatrixA(int nxval):
MatrixWithProduct<arcomplex<T> >(nxval*nxval)
/*
Constructor.
*/
{
nx = nxval;
} // constructor.
#endif // CMATRIXA_H
|