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
|
/*
ARPACK++ v1.0 8/1/1997
c++ interface to ARPACK code.
MODULE CMatrixD.h
Class template for the mass matrix formed by using
piecewise linear elements on [0,1].
ARPACK Authors
Richard Lehoucq
Danny Sorensen
Chao Yang
Dept. of Computational & Applied Mathematics
Rice University
Houston, Texas
*/
#ifndef CMATRIXD_H
#define CMATRIXD_H
#include "arcomp.h"
#include "matprod.h"
#include "blas1c.h"
#include "lapackc.h"
template<class T>
class ComplexMatrixD: public MatrixWithProduct<arcomplex<T> > {
private:
arcomplex<T> *Ad, *Adl, *Adu, *Adu2;
int *ipiv;
int decsize;
void FactorDataDeallocate();
// Eliminates the data structure used on matrix factorization.
public:
void FactorM();
// Factors B, a symmetric tridiagonal matrix with 4 on the
// main diagonal and 1 on the off-diagonals.
void MultMv(arcomplex<T> *v, arcomplex<T> *w);
// Performs the matrix-vector multiplication w <- M*v
void SolveM(arcomplex<T> *v);
// Solves M.w = v. v is overwritten with vector w.
ComplexMatrixD(int nx);
// Constructor
virtual ~ComplexMatrixD();
// Destructor
}; // ComplexMatrixD.
template<class T>
inline void ComplexMatrixD<T>::FactorDataDeallocate()
{
if (Ad != 0) {
delete[] Ad;
delete[] Adl;
delete[] Adu;
delete[] Adu2;
delete[] ipiv;
}
} // FactorDataDeallocate
template<class T>
void ComplexMatrixD<T>::FactorM()
{
int j, ierr;
arcomplex<T> h;
const arcomplex<T> one(1.0, 0.0);
const arcomplex<T> four(4.0, 0.0);
if (decsize != this->ncols()) {
decsize = this->ncols();
FactorDataDeallocate();
Ad = new arcomplex<T>[decsize];
Adl = new arcomplex<T>[decsize];
Adu = new arcomplex<T>[decsize];
Adu2 = new arcomplex<T>[decsize];
ipiv = new int[decsize];
}
h = one/arcomplex<T>((this->ncols()+1),0.0);
for (j=0; j<this->ncols()-1; j++) {
Adl[j] = one*h;
Ad[j] = four*h;
Adu[j] = one*h;
}
Ad[this->ncols()-1] = four*h;
gttrf(this->ncols(), Adl, Ad, Adu, Adu2, ipiv, ierr);
} // FactorM.
template<class T>
void ComplexMatrixD<T>::MultMv(arcomplex<T> *v, arcomplex<T> *w)
{
int j;
arcomplex<T> h;
const arcomplex<T> one(1.0, 0.0);
const arcomplex<T> four(4.0, 0.0);
w[0] = four*v[0] + one*v[1];
for (j=1; j<this->ncols()-1; j++) {
w[j] = one*v[j-1] + four*v[j] + one*v[j+1];
}
w[this->ncols()-1] = one*v[this->ncols()-2] + four*v[this->ncols()-1];
h = one/arcomplex<T>((this->ncols()+1),0.0);
scal(this->ncols(), h, w, 1);
} // MultMv.
template<class T>
inline void ComplexMatrixD<T>::SolveM(arcomplex<T> *v)
{
int ierr;
char *type = "N";
gttrs(type, this->ncols(), 1, Adl, Ad, Adu, Adu2, ipiv, v, this->ncols(), ierr);
} // SolveM.
template<class T>
inline ComplexMatrixD<T>::
ComplexMatrixD(int nx): MatrixWithProduct<arcomplex<T> >(nx)
{
decsize = 0;
Ad = 0;
Adl = 0;
Adu = 0;
Adu2 = 0;
ipiv = 0;
} // Constructor.
template<class T>
inline ComplexMatrixD<T>::~ComplexMatrixD()
{
FactorDataDeallocate();
} // Destructor.
#endif // CMATRIXD_H
|