[1941] | 1 | #ifndef TOEPLITZMATRIX_SEEN
|
---|
| 2 | #define TOEPLITZMATRIX_SEEN
|
---|
| 3 |
|
---|
| 4 |
|
---|
| 5 |
|
---|
| 6 | // matrice de Toeplitz reelle ou complexe
|
---|
| 7 | //------------------------------------------------------------------
|
---|
| 8 | // ***** Guy Le Meur -- LAL-Orsay mars 2002 ****************
|
---|
| 9 | //-------------------------------------------------------------------
|
---|
| 10 |
|
---|
| 11 |
|
---|
| 12 | #include "machdefs.h" // Definitions specifiques SOPHYA
|
---|
| 13 |
|
---|
| 14 | #include <math.h>
|
---|
[2322] | 15 | #include <iostream>
|
---|
[1941] | 16 |
|
---|
| 17 | #include "nbmath.h"
|
---|
| 18 | #include "timing.h"
|
---|
| 19 |
|
---|
| 20 | #include "array.h"
|
---|
| 21 |
|
---|
| 22 | #include "fftservintf.h"
|
---|
| 23 | #include "fftpserver.h"
|
---|
| 24 |
|
---|
| 25 | // classe pour decrire une matrice de Toeplitz reelle ou complexe,
|
---|
| 26 | // symetrique (hermitienne) ou non.
|
---|
| 27 | // Methodes de gradient conjugues pour resolution de systemes (uniquement
|
---|
| 28 | // pour symetriques ou hermitiennes, pour le moment)
|
---|
| 29 |
|
---|
[2806] | 30 | namespace SOPHYA {
|
---|
| 31 |
|
---|
[1941] | 32 | class Toeplitz
|
---|
| 33 | {
|
---|
| 34 |
|
---|
| 35 | private:
|
---|
| 36 | // verouiller le clonage
|
---|
| 37 | Toeplitz(const Toeplitz&) {}
|
---|
| 38 | Toeplitz &operator = (const Toeplitz&) {return *this;}
|
---|
| 39 |
|
---|
| 40 | public:
|
---|
| 41 |
|
---|
| 42 | Toeplitz();
|
---|
| 43 | Toeplitz(const TVector<complex<double> >& firstCol);
|
---|
| 44 |
|
---|
| 45 | ~Toeplitz();
|
---|
| 46 |
|
---|
| 47 | // toeplitz complexe generale
|
---|
| 48 | void setMatrix(const TVector<complex<double> >& firstCol, const TVector<complex<double> >& firstRow);
|
---|
| 49 | // toeplitz hermitienne
|
---|
| 50 | void setMatrix(const TVector<complex<double> >& firstCol);
|
---|
| 51 | // toeplitz reelle generale
|
---|
| 52 | void setMatrix(const TVector<double>& firstCol, const TVector<double>& firstRow);
|
---|
| 53 | // toeplitz reelle symetrique
|
---|
| 54 | void setMatrix(const TVector<double>& firstCol);
|
---|
| 55 |
|
---|
| 56 |
|
---|
| 57 | int gradientToeplitz(TVector<complex<double> >& b) const;
|
---|
| 58 | int gradientToeplitz(TVector<double>& b) const;
|
---|
| 59 |
|
---|
| 60 | int gradientToeplitzPreconTChang(TVector<complex<double> >& b) const;
|
---|
| 61 |
|
---|
| 62 | int CGSToeplitz(TVector<double>& b) const;
|
---|
| 63 | int DCGToeplitz(TVector<double>& b) ;
|
---|
| 64 |
|
---|
| 65 | private:
|
---|
| 66 |
|
---|
| 67 | inline complex<double> prodScalaire(int n, TVector<complex<double> >& v1, TVector<complex<double> >& v2) const
|
---|
| 68 | {
|
---|
| 69 | complex<double> produit = complex<double>(0.,0.);
|
---|
| 70 | for (int k =0; k<n; k++) produit += v1(k)*conj(v2(k));
|
---|
| 71 | return produit;
|
---|
| 72 | }
|
---|
| 73 | inline double prodScalaire(int n, TVector<double>& v1, TVector<double>& v2) const
|
---|
| 74 | {
|
---|
| 75 | double produit = 0.;
|
---|
| 76 | for (int k =0; k<n; k++) produit += v1(k)*v2(k);
|
---|
| 77 | return produit;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 |
|
---|
| 81 | inline void transformeeFourier(const TVector<complex<double> >& v, TVector< complex<double> >& tv) const
|
---|
| 82 | {
|
---|
| 83 | fftIntfPtr_-> FFTForward(v, tv);
|
---|
| 84 | }
|
---|
| 85 | inline void transformeeFourier(const TVector<double>& v, TVector< complex<double> >& tv) const
|
---|
| 86 | {
|
---|
| 87 | fftIntfPtr_-> FFTForward(v, tv);
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 |
|
---|
| 91 | inline void transformeeInverseFourier(const TVector<complex<double> >& tv, TVector<complex<double> >& v) const
|
---|
| 92 | {
|
---|
| 93 | int n= tv.Size();
|
---|
| 94 | fftIntfPtr_-> FFTBackward(tv, v);
|
---|
| 95 | v/=n;
|
---|
| 96 | }
|
---|
| 97 | inline void transformeeInverseFourier(const TVector<complex<double> >& tv, TVector<double>& v) const
|
---|
| 98 | {
|
---|
| 99 | int n= tv.Size();
|
---|
| 100 | fftIntfPtr_-> FFTBackward(tv, v);
|
---|
| 101 | double fac = 1./(2*(n-1));
|
---|
| 102 | v *= fac;
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | inline void initTFTransposeeToeplitzComplexe()
|
---|
| 106 | {
|
---|
| 107 | int k;
|
---|
| 108 | int ndyad = vecteurCirculant_.Size();
|
---|
| 109 | TVector<complex<double> > vecteurCirculantTranspose(ndyad);
|
---|
| 110 | vecteurCirculantTranspose = complex<double>(0.,0.);
|
---|
| 111 | vecteurCirculantTranspose(0) = vecteurCirculant_(0);
|
---|
| 112 | for (k=1; k< dimTop_; k++)
|
---|
| 113 | {
|
---|
| 114 | vecteurCirculantTranspose(k) = vecteurCirculant_(ndyad-k);
|
---|
| 115 | vecteurCirculantTranspose(ndyad-k) = vecteurCirculant_(k);
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | transformeeFourier(vecteurCirculantTranspose, CirculanteTransposeeFourier_);
|
---|
| 119 | }
|
---|
| 120 | inline void initTFTransposeeToeplitzReelle()
|
---|
| 121 | {
|
---|
| 122 | int k;
|
---|
| 123 | int ndyad = vecteurCirculantD_.Size();
|
---|
| 124 | TVector<double> vecteurCirculantTranspose(ndyad);
|
---|
| 125 | vecteurCirculantTranspose = 0.;
|
---|
| 126 | vecteurCirculantTranspose(0) = vecteurCirculantD_(0);
|
---|
| 127 | for (k=1; k< dimTop_; k++)
|
---|
| 128 | {
|
---|
| 129 | vecteurCirculantTranspose(k) = vecteurCirculantD_(ndyad-k);
|
---|
| 130 | vecteurCirculantTranspose(ndyad-k) = vecteurCirculantD_(k);
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | transformeeFourier(vecteurCirculantTranspose, CirculanteTransposeeFourier_);
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | void extensionACirculanteDyadique(const TVector<complex<double> >& firstCol, const TVector<complex<double> >& firstRow);
|
---|
| 137 |
|
---|
| 138 | void extensionACirculanteDyadique(const TVector<double>& firstCol, const TVector<double>& firstRow);
|
---|
| 139 | void extensionACirculanteDyadique(const TVector<complex<double> >& firstCol);
|
---|
| 140 |
|
---|
| 141 | void extensionACirculanteDyadique(const TVector<double>& firstCol);
|
---|
| 142 |
|
---|
| 143 |
|
---|
| 144 | // matrice circulante entree par sa T. de Fourier
|
---|
| 145 | void produitParVecFourier(const TVector<complex<double> >& q, TVector<complex<double> >& Tq) const;
|
---|
| 146 | void produitParVecFourier(const TVector<double>& q, TVector<double>& Tq) const;
|
---|
| 147 |
|
---|
| 148 | void produitTransposeeParVecFourier(const TVector<double>& q, TVector<double>& Tq) const;
|
---|
| 149 |
|
---|
| 150 |
|
---|
| 151 | // preconditionneur pour une Toeplitz HERMITIENNE
|
---|
| 152 | // LE RESUTAT EST UNE TRANSFORMEE DE FOURIER
|
---|
| 153 | void fabricationTChangPreconHerm(TVector<complex<double> >& TFourierC) const;
|
---|
| 154 |
|
---|
| 155 | // matrice circulante entree par sa T. de Fourier
|
---|
| 156 | void inverseSystemeCirculantFourier(const TVector<complex<double> >& TFourierC, const TVector<complex<double> >& secondMembre, TVector<complex<double> >& resul) const;
|
---|
| 157 |
|
---|
| 158 |
|
---|
| 159 | void expliciteCirculante(TMatrix<complex<double> >& m) const;
|
---|
| 160 | void expliciteToeplitz(TMatrix<complex<double> >& m) const;
|
---|
| 161 | void expliciteToeplitz(TMatrix<double>& m) const;
|
---|
| 162 |
|
---|
| 163 |
|
---|
| 164 | bool hermitian_;
|
---|
| 165 | int dimTop_;
|
---|
| 166 | TVector<complex<double> > vecteurCirculant_;
|
---|
| 167 | TVector<double> vecteurCirculantD_;
|
---|
| 168 | TVector<complex<double> > CirculanteFourier_;
|
---|
| 169 | TVector<complex<double> > CirculanteTransposeeFourier_;
|
---|
| 170 | FFTServerInterface* fftIntfPtr_;
|
---|
| 171 | };
|
---|
| 172 |
|
---|
| 173 |
|
---|
| 174 | // fin classe Toeplitz
|
---|
| 175 |
|
---|
| 176 |
|
---|
[2806] | 177 | } // Fin du namespace
|
---|
| 178 |
|
---|
[1941] | 179 | #endif
|
---|