| [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 | 
 | 
|---|
 | 30 | class Toeplitz
 | 
|---|
 | 31 | {
 | 
|---|
 | 32 | 
 | 
|---|
 | 33 |  private: 
 | 
|---|
 | 34 |   // verouiller le clonage
 | 
|---|
 | 35 | Toeplitz(const Toeplitz&)  {}
 | 
|---|
 | 36 | Toeplitz &operator = (const Toeplitz&) {return *this;}
 | 
|---|
 | 37 | 
 | 
|---|
 | 38 | public:
 | 
|---|
 | 39 | 
 | 
|---|
 | 40 | Toeplitz();
 | 
|---|
 | 41 | Toeplitz(const TVector<complex<double> >& firstCol);
 | 
|---|
 | 42 | 
 | 
|---|
 | 43 | ~Toeplitz();
 | 
|---|
 | 44 | 
 | 
|---|
 | 45 |   // toeplitz complexe generale
 | 
|---|
 | 46 |   void  setMatrix(const TVector<complex<double> >& firstCol, const TVector<complex<double> >& firstRow); 
 | 
|---|
 | 47 |   // toeplitz hermitienne
 | 
|---|
 | 48 |   void  setMatrix(const TVector<complex<double> >& firstCol); 
 | 
|---|
 | 49 |   // toeplitz reelle generale
 | 
|---|
 | 50 |   void  setMatrix(const TVector<double>& firstCol, const TVector<double>& firstRow); 
 | 
|---|
 | 51 |   // toeplitz reelle symetrique
 | 
|---|
 | 52 |   void  setMatrix(const TVector<double>& firstCol); 
 | 
|---|
 | 53 | 
 | 
|---|
 | 54 | 
 | 
|---|
 | 55 |   int gradientToeplitz(TVector<complex<double> >& b) const;
 | 
|---|
 | 56 |   int gradientToeplitz(TVector<double>& b) const;
 | 
|---|
 | 57 | 
 | 
|---|
 | 58 |   int gradientToeplitzPreconTChang(TVector<complex<double> >& b) const;
 | 
|---|
 | 59 | 
 | 
|---|
 | 60 |   int CGSToeplitz(TVector<double>& b) const;
 | 
|---|
 | 61 |   int DCGToeplitz(TVector<double>& b) ;
 | 
|---|
 | 62 | 
 | 
|---|
 | 63 | private:
 | 
|---|
 | 64 | 
 | 
|---|
 | 65 | inline complex<double> prodScalaire(int n,  TVector<complex<double> >& v1, TVector<complex<double> >& v2) const
 | 
|---|
 | 66 | {
 | 
|---|
 | 67 |   complex<double> produit = complex<double>(0.,0.);
 | 
|---|
 | 68 |   for (int k =0; k<n; k++) produit += v1(k)*conj(v2(k));
 | 
|---|
 | 69 |   return produit;
 | 
|---|
 | 70 | }
 | 
|---|
 | 71 | inline double prodScalaire(int n,  TVector<double>& v1, TVector<double>& v2) const
 | 
|---|
 | 72 | {
 | 
|---|
 | 73 |   double produit = 0.;
 | 
|---|
 | 74 |   for (int k =0; k<n; k++) produit += v1(k)*v2(k);
 | 
|---|
 | 75 |   return produit;
 | 
|---|
 | 76 | }
 | 
|---|
 | 77 | 
 | 
|---|
 | 78 | 
 | 
|---|
 | 79 | inline void transformeeFourier(const TVector<complex<double> >& v, TVector< complex<double> >& tv) const
 | 
|---|
 | 80 | {
 | 
|---|
 | 81 |   fftIntfPtr_-> FFTForward(v, tv);
 | 
|---|
 | 82 | } 
 | 
|---|
 | 83 | inline void transformeeFourier(const TVector<double>& v, TVector< complex<double> >& tv) const
 | 
|---|
 | 84 | {
 | 
|---|
 | 85 |   fftIntfPtr_-> FFTForward(v, tv);
 | 
|---|
 | 86 | } 
 | 
|---|
 | 87 | 
 | 
|---|
 | 88 | 
 | 
|---|
 | 89 | inline void transformeeInverseFourier(const TVector<complex<double> >& tv, TVector<complex<double> >& v) const
 | 
|---|
 | 90 | {
 | 
|---|
 | 91 |   int n= tv.Size();
 | 
|---|
 | 92 |   fftIntfPtr_-> FFTBackward(tv, v);
 | 
|---|
 | 93 |   v/=n;
 | 
|---|
 | 94 | } 
 | 
|---|
 | 95 | inline void transformeeInverseFourier(const TVector<complex<double> >& tv, TVector<double>& v) const
 | 
|---|
 | 96 | {
 | 
|---|
 | 97 |   int n= tv.Size();
 | 
|---|
 | 98 |   fftIntfPtr_-> FFTBackward(tv, v);
 | 
|---|
 | 99 |   double fac = 1./(2*(n-1));
 | 
|---|
 | 100 |   v *= fac;
 | 
|---|
 | 101 | } 
 | 
|---|
 | 102 | 
 | 
|---|
 | 103 | inline void initTFTransposeeToeplitzComplexe() 
 | 
|---|
 | 104 | {
 | 
|---|
 | 105 |   int k;
 | 
|---|
 | 106 |   int ndyad = vecteurCirculant_.Size();
 | 
|---|
 | 107 |   TVector<complex<double> > vecteurCirculantTranspose(ndyad);
 | 
|---|
 | 108 |   vecteurCirculantTranspose =  complex<double>(0.,0.);
 | 
|---|
 | 109 |   vecteurCirculantTranspose(0) = vecteurCirculant_(0);
 | 
|---|
 | 110 |   for (k=1; k< dimTop_; k++)
 | 
|---|
 | 111 |     {
 | 
|---|
 | 112 |       vecteurCirculantTranspose(k) = vecteurCirculant_(ndyad-k);
 | 
|---|
 | 113 |       vecteurCirculantTranspose(ndyad-k) = vecteurCirculant_(k);
 | 
|---|
 | 114 |     }
 | 
|---|
 | 115 | 
 | 
|---|
 | 116 |   transformeeFourier(vecteurCirculantTranspose, CirculanteTransposeeFourier_);
 | 
|---|
 | 117 | }
 | 
|---|
 | 118 | inline void initTFTransposeeToeplitzReelle() 
 | 
|---|
 | 119 | {
 | 
|---|
 | 120 |   int k;
 | 
|---|
 | 121 |   int ndyad = vecteurCirculantD_.Size();
 | 
|---|
 | 122 |   TVector<double> vecteurCirculantTranspose(ndyad);
 | 
|---|
 | 123 |   vecteurCirculantTranspose =  0.;
 | 
|---|
 | 124 |   vecteurCirculantTranspose(0) = vecteurCirculantD_(0);
 | 
|---|
 | 125 |   for (k=1; k< dimTop_; k++)
 | 
|---|
 | 126 |     {
 | 
|---|
 | 127 |       vecteurCirculantTranspose(k) = vecteurCirculantD_(ndyad-k);
 | 
|---|
 | 128 |       vecteurCirculantTranspose(ndyad-k) = vecteurCirculantD_(k);
 | 
|---|
 | 129 |     }
 | 
|---|
 | 130 | 
 | 
|---|
 | 131 |   transformeeFourier(vecteurCirculantTranspose, CirculanteTransposeeFourier_);
 | 
|---|
 | 132 | }
 | 
|---|
 | 133 | 
 | 
|---|
 | 134 | void extensionACirculanteDyadique(const TVector<complex<double> >& firstCol, const TVector<complex<double> >& firstRow);
 | 
|---|
 | 135 | 
 | 
|---|
 | 136 | void extensionACirculanteDyadique(const TVector<double>& firstCol, const TVector<double>& firstRow);
 | 
|---|
 | 137 | void extensionACirculanteDyadique(const TVector<complex<double> >& firstCol);
 | 
|---|
 | 138 | 
 | 
|---|
 | 139 | void extensionACirculanteDyadique(const TVector<double>& firstCol);
 | 
|---|
 | 140 | 
 | 
|---|
 | 141 | 
 | 
|---|
 | 142 | // matrice circulante entree par sa T. de Fourier
 | 
|---|
 | 143 | void produitParVecFourier(const TVector<complex<double> >& q, TVector<complex<double> >& Tq) const;
 | 
|---|
 | 144 | void produitParVecFourier(const TVector<double>& q, TVector<double>& Tq) const;
 | 
|---|
 | 145 | 
 | 
|---|
 | 146 | void produitTransposeeParVecFourier(const TVector<double>& q, TVector<double>& Tq) const;
 | 
|---|
 | 147 | 
 | 
|---|
 | 148 | 
 | 
|---|
 | 149 | // preconditionneur pour une Toeplitz HERMITIENNE
 | 
|---|
 | 150 | // LE RESUTAT EST UNE TRANSFORMEE DE FOURIER
 | 
|---|
 | 151 | void fabricationTChangPreconHerm(TVector<complex<double> >& TFourierC) const;
 | 
|---|
 | 152 | 
 | 
|---|
 | 153 | // matrice circulante entree par sa T. de Fourier
 | 
|---|
 | 154 | void inverseSystemeCirculantFourier(const TVector<complex<double> >& TFourierC, const TVector<complex<double> >& secondMembre, TVector<complex<double> >& resul) const;
 | 
|---|
 | 155 | 
 | 
|---|
 | 156 | 
 | 
|---|
 | 157 | void expliciteCirculante(TMatrix<complex<double> >& m) const;
 | 
|---|
 | 158 | void expliciteToeplitz(TMatrix<complex<double> >& m) const;
 | 
|---|
 | 159 | void expliciteToeplitz(TMatrix<double>& m) const;
 | 
|---|
 | 160 | 
 | 
|---|
 | 161 | 
 | 
|---|
 | 162 |   bool hermitian_;
 | 
|---|
 | 163 |   int dimTop_;
 | 
|---|
 | 164 |   TVector<complex<double> > vecteurCirculant_;
 | 
|---|
 | 165 |   TVector<double> vecteurCirculantD_;
 | 
|---|
 | 166 |   TVector<complex<double> > CirculanteFourier_;
 | 
|---|
 | 167 |   TVector<complex<double> > CirculanteTransposeeFourier_;
 | 
|---|
 | 168 |   FFTServerInterface* fftIntfPtr_;
 | 
|---|
 | 169 | };
 | 
|---|
 | 170 | 
 | 
|---|
 | 171 | 
 | 
|---|
 | 172 | // fin classe Toeplitz
 | 
|---|
 | 173 | 
 | 
|---|
 | 174 | 
 | 
|---|
 | 175 | #endif
 | 
|---|