Changeset 3510 in Sophya for trunk/SophyaLib/Samba


Ignore:
Timestamp:
Aug 8, 2008, 3:11:45 PM (17 years ago)
Author:
ansari
Message:

Nettoyage alm.h .cc , utilisation RandomGenerator par Alm<T> et SphericalTransformServer , Reza 08/08/2008

Location:
trunk/SophyaLib/Samba
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/Samba/alm.cc

    r2885 r3510  
    11#include "sopnamsp.h"
    22#include "alm.h"
     3
     4
     5/*!
     6  \class Alm
     7  \ingroup Samba
     8  Class for manipulating the coefficients \f$a_{lm}\f$ of the development
     9  in spherical harmonics of  a function efined on a sphere.
     10*/
     11 
     12/*!
     13  fwhm specifies the gaussian beam half witdh in arc.minutes
     14*/
    315template <class T>
    416Alm<T>::Alm(const TVector<T>& clin, const r_8 fwhm)
    517
    618{
     19  int_4 nlmax= clin.NElts()-1;
     20
     21  //alm.ReSize(nlmax);
     22  this->ReSizeRow(nlmax+1);
     23  RandomGenerator rg(1, false);
     24  GenFromCl(clin, fwhm, rg);
     25}
     26
     27/*!
     28  fwhm specifies the gaussian beam half witdh in arc.minutes
     29*/
     30template <class T>
     31Alm<T>::Alm(const TVector<T>& clin, const r_8 fwhm, RandomGenerator & rg)
     32{
     33  int_4 nlmax= clin.NElts()-1;
     34
     35  //alm.ReSize(nlmax);
     36  this->ReSizeRow(nlmax+1);
     37  GenFromCl(clin, fwhm, rg); 
     38}
    739
    840
     41
     42template <class T>
     43void Alm<T>::GenFromCl(const TVector<T> & clin, const r_8 fwhm, RandomGenerator & rg)
     44{
    945  /*=======================================================================
    1046     creates the a_lm from the power spectrum,
     
    2157  int_4 nlmax= clin.NElts()-1;
    2258
    23   //alm.ReSize(nlmax);
    24   this->ReSizeRow(nlmax+1);
    25 
    2659  r_8 sig_smooth = fwhm/sqrt(8.*log(2.))/(60.*180.)* M_PI;
    2760  int_4 n_l = nlmax+1;
     
    2962
    3063  //    --- smoothes the initial power spectrum ---
    31   TVector<T> cl=clin;
     64  TVector<T> cl(clin, false);
    3265  int l;
    3366  for (l=0;l<n_l;l++)
     
    4578      T rms=sqrt(cl(l));
    4679      //        ------ m = 0 ------
    47       complex<T> zeta1(NorRand());
     80      complex<T> zeta1((T)rg.Gaussian() );
    4881      (*this)(l,0)   = zeta1 * rms;
    4982
     
    5285        {
    5386          complex<T> aux1(hsqrt2);
    54           complex<T> aux2(NorRand(),NorRand());
     87          complex<T> aux2((T)rg.Gaussian() , (T)rg.Gaussian() );
    5588          zeta1=aux1*aux2;
    5689          (*this)(l,m)=rms*zeta1;
     
    79112  return powsp;
    80113}
     114
     115/*!
     116  \class Bm
     117  \ingroup Samba
     118  Class for a vector with an index running from \f$-m_{max}\f$ to \f$+m_{max}\f$
     119  (then the size of the vector will be actually \f$2m_{max}+1)\f$.
     120  This class is used by the spherical harmonics transform server
     121*/
     122
    81123 
    82124#ifdef __CXX_PRAGMA_TEMPLATES__
  • trunk/SophyaLib/Samba/alm.h

    r3077 r3510  
    66#define ALM_SEEN
    77
    8 #include "srandgen.h"
     8#include "stsrand.h"
    99#include "nbmath.h"
    1010#include "triangmtx.h"
     
    1313namespace SOPHYA { 
    1414
    15 /*! class for the coefficients \f$a_{lm}\f$ of the development of a function defined on a sphere, in spherical harmonics */
     15// ----- Classe Alm
    1616template <class T>
    17 class Alm : public TriangularMatrix<complex<T> >
    18   {
    19     public :
     17class Alm : public TriangularMatrix< complex<T> > {
     18public :
    2019 
    21 Alm() : TriangularMatrix<complex<T> >()  {;};
    22     /* instanciate the class from the maximum value of the index \f$l\f$ in the sequence of the \f$a_{lm}\f$'s */
    23 Alm(sa_size_t nlmax) : TriangularMatrix<complex<T> >(nlmax+1) {;}
    24 Alm(const Alm<T>& a,  bool share=false)  : TriangularMatrix<complex<T> >(a, share)  {;}
     20  Alm() : TriangularMatrix<complex<T> >()  {}
     21//! instanciate the class from the maximum value of the index \f$l\f$ in the sequence of the \f$a_{lm}\f$'s
     22  Alm(sa_size_t nlmax) : TriangularMatrix<complex<T> >(nlmax+1) {}
     23//! copy constructor
     24  Alm(const Alm<T>& a,  bool share=false)  : TriangularMatrix<complex<T> >(a, share)  {}
     25//! Constructor, generates alm from a cl vector
     26  Alm(const TVector<T> & clin, const r_8 fwhm) ;
     27//! Constructor, generates alm from a cl vector, using the specified random generator object
     28  Alm(const TVector<T> & clin, const r_8 fwhm, RandomGenerator & rg);
    2529
    26 Alm(const TVector<T>& clin, const r_8 fwhm) ;
    27 /*! resize with a new lmax */
    28 inline void ReSizeToLmax(sa_size_t nlmax) {this->ReSizeRow(nlmax+1);}
    29 inline sa_size_t Lmax() const {return this->rowNumber()-1;}
    30 TVector<T> powerSpectrum() const;
     30//! Resize with a new lmax
     31  inline void ReSizeToLmax(sa_size_t nlmax) {this->ReSizeRow(nlmax+1);}
     32  inline sa_size_t Lmax() const {return this->rowNumber()-1;}
    3133
    32 inline  Alm<T>& SetComplexT(complex<T> a)
    33    {
    34      this->SetT(a);
    35      return *this;
    36    }
    37  inline Alm<T>& operator = (complex<T> a)
    38  {
    39    return SetComplexT(a);
    40  }
     34//! Computes the corresponding pwer spectrum (Cl vector)
     35  TVector<T> powerSpectrum() const;
    4136
     37  inline  Alm<T>& SetComplexT(complex<T> a)
     38    {  this->SetT(a);  return *this;  }
     39  inline Alm<T>& operator = (complex<T> a)
     40    {  return SetComplexT(a);  }
     41
     42private:
     43  void GenFromCl(const TVector<T> & clin, const r_8 fwhm, RandomGenerator& rg);
    4244};
    43 /*! class for a vector with an index running from \f$-m_{max}\f$ to \f$+m_{max}\f$ (then the size of the vector will be actually \f$2m_{max}+1)\f$ */
     45
     46
     47//------------ Classe Bm , vecteur avec index  -mMax <= index <= +mMax
    4448template <class T>
    45 class Bm
    46   {
    47     public :
    48 Bm(): nmmax_(0) {;};
    49     /* instanciate from the maximum absolute value of the index */
    50 Bm(sa_size_t mmax) : nmmax_(mmax)   { bm_.ReSize( (2*mmax+1) );}
    51  Bm(const Bm<T>& b,  bool share=false) : nmmax_(b.nmmax_), bm_(b.bm_, share) {;}
    52  /*! resize with a new value of mmax */
    53 inline void ReSizeToMmax(sa_size_t mmax)
    54   {
    55     nmmax_= mmax;
    56     bm_.ReSize(2* nmmax_+1);
    57   }
    58 //inline sa_size_t Size() const {return 2*nmmax_+1;};
    59 inline T& operator()(sa_size_t m) {return bm_( adr_i(m));};
    60 inline T const& operator()(sa_size_t m) const {return *(bm_.Begin()+ adr_i(m));};
    61 /*! return the current value of the maximum absolute value of the index */
    62 inline sa_size_t Mmax() const
    63    {
    64      return nmmax_;
    65    }
    66 inline Bm<T>& operator = (const Bm<T>& b)
    67  {
    68    if (this != &b)
    69      {
     49class Bm  {
     50public :
     51  Bm(): nmmax_(0) {;};
     52//! Constructor with the specification of the maximum absolute value of the index : |mMax|
     53//! Copy contrsuctor
     54  Bm(sa_size_t mmax) : nmmax_(mmax)   { bm_.ReSize( (2*mmax+1) );}
     55  Bm(const Bm<T>& b,  bool share=false) : nmmax_(b.nmmax_), bm_(b.bm_, share) { }
     56 //! resize with a new value of mmax
     57  inline void ReSizeToMmax(sa_size_t mmax)
     58    { nmmax_= mmax; bm_.ReSize(2* nmmax_+1); }
     59
     60//! Acces to element with index m  ( -mMax <= m <= +mMax  )
     61  inline T operator()(sa_size_t m) const { return bm_( m+nmmax_); }
     62//! Acces to element with index m  ( -mMax <= m <= +mMax  )
     63  inline T& operator()(sa_size_t m) { return bm_( m+nmmax_); }
     64
     65//! Return the current value of the maximum absolute value of the index
     66  inline sa_size_t Mmax() const   { return nmmax_; }
     67
     68  inline Bm<T>& operator = (const Bm<T>& b)
     69    {
     70    if (this != &b) {
    7071       nmmax_= b.nmmax_;
    7172       bm_=  b.bm_;
    72      }
    73    return *this;
    74  }
    75 
    76   private:
    77 /*! return the address in the array representing the vector */
    78 inline sa_size_t adr_i(sa_size_t i) const
    79 {
    80   return (i+nmmax_);
    81 }
     73       }
     74    return *this;
     75    }
    8276
    8377
    84 
    85  sa_size_t nmmax_;
    86  NDataBlock<T> bm_;
    87 
     78 private:
     79  sa_size_t nmmax_;
     80  NDataBlock<T> bm_;
    8881  };
    8982
  • trunk/SophyaLib/Samba/sphericaltransformserver.cc

    r3508 r3510  
    66#include "sphericaltransformserver.h"
    77#include "tvector.h"
    8 #include "srandgen.h"
     8#include "stsrand.h"
    99#include "nbmath.h"
    1010#include "timing.h"
     
    152152
    153153 */
     154
     155//!  Default constructor - Creates a non thread-safe RandomGenerator to be used by GenerateFromCl
     156template<class T>
     157SphericalTransformServer<T>::SphericalTransformServer()
     158: rg_(1, false)
     159{
     160  fftIntfPtr_=new FFTPackServer(true); // preserveinput = true
     161  fftIntfPtr_->setNormalize(false);
     162}
     163
     164//!  Constructor with the specification of a RandomGenerator object to be used by GenerateFromCl
     165template<class T>
     166SphericalTransformServer<T>::SphericalTransformServer(RandomGenerator const & rg)
     167: rg_(rg)
     168{
     169  fftIntfPtr_=new FFTPackServer(true); // preserveinput = true
     170  fftIntfPtr_->setNormalize(false);
     171}
     172
     173template<class T>
     174SphericalTransformServer<T>::~SphericalTransformServer()
     175{
     176  if (fftIntfPtr_!=NULL) delete fftIntfPtr_;
     177}
     178
     179/*!
     180 Set a fft server. The constructor sets a default fft server (fft-pack).
     181 So it is not necessary to call this method for a standard use.
     182 \warning The FFTServerInterface object should NOT overwrite the input arrays
     183*/
     184template<class T>
     185void SphericalTransformServer<T>::SetFFTServer(FFTServerInterface* srv)
     186{
     187  if (fftIntfPtr_!=NULL) delete fftIntfPtr_;
     188  fftIntfPtr_=srv;
     189  fftIntfPtr_->setNormalize(false);
     190}
     191
    154192
    155193 /*! \fn void SOPHYA::SphericalTransformServer::GenerateFromAlm( SphericalMap<T>& map, int_4 pixelSizeIndex, const Alm<T>& alm) const
     
    12751313  //  Alm<T> a2lme = almFromCl(Cle, fwhm);
    12761314  // Alm<T> a2lmb = almFromCl(Clb, fwhm);
    1277   Alm<T> a2lme(Cle, fwhm);
    1278   Alm<T> a2lmb(Clb, fwhm);
     1315  Alm<T> a2lme(Cle, fwhm, rg_);
     1316  Alm<T> a2lmb(Clb, fwhm, rg_);
    12791317
    12801318  GenerateFromAlm(sphq,sphu,pixelSizeIndex,a2lme,a2lmb);
     
    12931331{
    12941332
    1295   Alm<T> alm(Cl, fwhm);
     1333  Alm<T> alm(Cl, fwhm, rg_);
    12961334  GenerateFromAlm(sph,pixelSizeIndex, alm );
    12971335}
  • trunk/SophyaLib/Samba/sphericaltransformserver.h

    r3003 r3510  
    55#include "fftservintf.h"
    66#include "fftpserver.h"
     7#include "stsrand.h"
    78#include "alm.h"
    89#include "lambdaBuilder.h"
     
    1819 public:
    1920
    20   SphericalTransformServer() 
    21     {
    22       fftIntfPtr_=new FFTPackServer(true); // preserveinput = true
    23       fftIntfPtr_->setNormalize(false);
    24     };
    25   ~SphericalTransformServer(){ if (fftIntfPtr_!=NULL) delete fftIntfPtr_;};
     21  SphericalTransformServer(); 
     22  SphericalTransformServer(RandomGenerator const & rg); 
     23  virtual ~SphericalTransformServer();
     24  void SetFFTServer(FFTServerInterface* srv=NULL);
    2625 
    27  /*!
    28  Set a fft server. The constructor sets a default fft server (fft-pack). So it is not necessary to call this method for a standard use.
    29  \warning The FFTServerInterface object should NOT overwrite the input arrays
    30 */
    31   void SetFFTServer(FFTServerInterface* srv=NULL)
    32     {
    33       if (fftIntfPtr_!=NULL) delete fftIntfPtr_;
    34       fftIntfPtr_=srv;
    35       fftIntfPtr_->setNormalize(false);
    36     }
    3726
    3827  void GenerateFromAlm( SphericalMap<T>& map, int_4 pixelSizeIndex, const Alm<T>& alm) const;
     
    4433                     int_4 pixelSizeIndex,
    4534                     const TVector<T>& Cle, const TVector<T>& Clb,
    46                     const r_8 fwhm) const;
     35                     const r_8 fwhm) const;
    4736
    4837
     
    118107
    119108 FFTServerInterface* fftIntfPtr_;
     109 mutable RandomGenerator rg_;
    120110
    121111};
Note: See TracChangeset for help on using the changeset viewer.