| 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>
 | 
|---|
| 15 | #include <iostream>
 | 
|---|
| 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 | namespace SOPHYA {
 | 
|---|
| 31 | 
 | 
|---|
| 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 | // Reza+CMV du 3/7/2006 : on a instancie le FFTPackServer avec le flag preserveinput=true
 | 
|---|
| 82 | // On peut donc faire en principe les const_cast sans danger 
 | 
|---|
| 83 | inline void transformeeFourier(const TVector<complex<double> >& v, TVector< complex<double> >& tv) const
 | 
|---|
| 84 | {
 | 
|---|
| 85 |   fftIntfPtr_-> FFTForward(const_cast<TVector<complex<double> > & >(v), tv);
 | 
|---|
| 86 | } 
 | 
|---|
| 87 | inline void transformeeFourier(const TVector<double>& v, TVector< complex<double> >& tv) const
 | 
|---|
| 88 | {
 | 
|---|
| 89 |   fftIntfPtr_-> FFTForward(const_cast<TVector<double> & >(v), tv);
 | 
|---|
| 90 | } 
 | 
|---|
| 91 | 
 | 
|---|
| 92 | 
 | 
|---|
| 93 | inline void transformeeInverseFourier(const TVector<complex<double> >& tv, TVector<complex<double> >& v) const
 | 
|---|
| 94 | {
 | 
|---|
| 95 |   int n= tv.Size();
 | 
|---|
| 96 |   fftIntfPtr_-> FFTBackward(const_cast<TVector<complex<double> > & >(tv), v);
 | 
|---|
| 97 |   v/=n;
 | 
|---|
| 98 | } 
 | 
|---|
| 99 | inline void transformeeInverseFourier(const TVector<complex<double> >& tv, TVector<double>& v) const
 | 
|---|
| 100 | {
 | 
|---|
| 101 |   int n= tv.Size();
 | 
|---|
| 102 |   fftIntfPtr_-> FFTBackward(const_cast< TVector<complex<double> > & >(tv), v);
 | 
|---|
| 103 |   double fac = 1./(2*(n-1));
 | 
|---|
| 104 |   v *= fac;
 | 
|---|
| 105 | } 
 | 
|---|
| 106 | 
 | 
|---|
| 107 | inline void initTFTransposeeToeplitzComplexe() 
 | 
|---|
| 108 | {
 | 
|---|
| 109 |   int k;
 | 
|---|
| 110 |   int ndyad = vecteurCirculant_.Size();
 | 
|---|
| 111 |   TVector<complex<double> > vecteurCirculantTranspose(ndyad);
 | 
|---|
| 112 |   vecteurCirculantTranspose =  complex<double>(0.,0.);
 | 
|---|
| 113 |   vecteurCirculantTranspose(0) = vecteurCirculant_(0);
 | 
|---|
| 114 |   for (k=1; k< dimTop_; k++)
 | 
|---|
| 115 |     {
 | 
|---|
| 116 |       vecteurCirculantTranspose(k) = vecteurCirculant_(ndyad-k);
 | 
|---|
| 117 |       vecteurCirculantTranspose(ndyad-k) = vecteurCirculant_(k);
 | 
|---|
| 118 |     }
 | 
|---|
| 119 | 
 | 
|---|
| 120 |   transformeeFourier(vecteurCirculantTranspose, CirculanteTransposeeFourier_);
 | 
|---|
| 121 | }
 | 
|---|
| 122 | inline void initTFTransposeeToeplitzReelle() 
 | 
|---|
| 123 | {
 | 
|---|
| 124 |   int k;
 | 
|---|
| 125 |   int ndyad = vecteurCirculantD_.Size();
 | 
|---|
| 126 |   TVector<double> vecteurCirculantTranspose(ndyad);
 | 
|---|
| 127 |   vecteurCirculantTranspose =  0.;
 | 
|---|
| 128 |   vecteurCirculantTranspose(0) = vecteurCirculantD_(0);
 | 
|---|
| 129 |   for (k=1; k< dimTop_; k++)
 | 
|---|
| 130 |     {
 | 
|---|
| 131 |       vecteurCirculantTranspose(k) = vecteurCirculantD_(ndyad-k);
 | 
|---|
| 132 |       vecteurCirculantTranspose(ndyad-k) = vecteurCirculantD_(k);
 | 
|---|
| 133 |     }
 | 
|---|
| 134 | 
 | 
|---|
| 135 |   transformeeFourier(vecteurCirculantTranspose, CirculanteTransposeeFourier_);
 | 
|---|
| 136 | }
 | 
|---|
| 137 | 
 | 
|---|
| 138 | void extensionACirculanteDyadique(const TVector<complex<double> >& firstCol, const TVector<complex<double> >& firstRow);
 | 
|---|
| 139 | 
 | 
|---|
| 140 | void extensionACirculanteDyadique(const TVector<double>& firstCol, const TVector<double>& firstRow);
 | 
|---|
| 141 | void extensionACirculanteDyadique(const TVector<complex<double> >& firstCol);
 | 
|---|
| 142 | 
 | 
|---|
| 143 | void extensionACirculanteDyadique(const TVector<double>& firstCol);
 | 
|---|
| 144 | 
 | 
|---|
| 145 | 
 | 
|---|
| 146 | // matrice circulante entree par sa T. de Fourier
 | 
|---|
| 147 | void produitParVecFourier(const TVector<complex<double> >& q, TVector<complex<double> >& Tq) const;
 | 
|---|
| 148 | void produitParVecFourier(const TVector<double>& q, TVector<double>& Tq) const;
 | 
|---|
| 149 | 
 | 
|---|
| 150 | void produitTransposeeParVecFourier(const TVector<double>& q, TVector<double>& Tq) const;
 | 
|---|
| 151 | 
 | 
|---|
| 152 | 
 | 
|---|
| 153 | // preconditionneur pour une Toeplitz HERMITIENNE
 | 
|---|
| 154 | // LE RESUTAT EST UNE TRANSFORMEE DE FOURIER
 | 
|---|
| 155 | void fabricationTChangPreconHerm(TVector<complex<double> >& TFourierC) const;
 | 
|---|
| 156 | 
 | 
|---|
| 157 | // matrice circulante entree par sa T. de Fourier
 | 
|---|
| 158 | void inverseSystemeCirculantFourier(const TVector<complex<double> >& TFourierC, const TVector<complex<double> >& secondMembre, TVector<complex<double> >& resul) const;
 | 
|---|
| 159 | 
 | 
|---|
| 160 | 
 | 
|---|
| 161 | void expliciteCirculante(TMatrix<complex<double> >& m) const;
 | 
|---|
| 162 | void expliciteToeplitz(TMatrix<complex<double> >& m) const;
 | 
|---|
| 163 | void expliciteToeplitz(TMatrix<double>& m) const;
 | 
|---|
| 164 | 
 | 
|---|
| 165 | 
 | 
|---|
| 166 |   bool hermitian_;
 | 
|---|
| 167 |   int dimTop_;
 | 
|---|
| 168 |   TVector<complex<double> > vecteurCirculant_;
 | 
|---|
| 169 |   TVector<double> vecteurCirculantD_;
 | 
|---|
| 170 |   TVector<complex<double> > CirculanteFourier_;
 | 
|---|
| 171 |   TVector<complex<double> > CirculanteTransposeeFourier_;
 | 
|---|
| 172 |   FFTServerInterface* fftIntfPtr_;
 | 
|---|
| 173 | };
 | 
|---|
| 174 | 
 | 
|---|
| 175 | 
 | 
|---|
| 176 | // fin classe Toeplitz
 | 
|---|
| 177 | 
 | 
|---|
| 178 | 
 | 
|---|
| 179 | }  // Fin du namespace
 | 
|---|
| 180 | 
 | 
|---|
| 181 | #endif
 | 
|---|