| 1 | #ifndef GENEFLUCT3D_SEEN
 | 
|---|
| 2 | #define GENEFLUCT3D_SEEN
 | 
|---|
| 3 | 
 | 
|---|
| 4 | #include "machdefs.h"
 | 
|---|
| 5 | #include "genericfunc.h"
 | 
|---|
| 6 | #include "tarray.h"
 | 
|---|
| 7 | #include "histerr.h"
 | 
|---|
| 8 | #include "hist2err.h"
 | 
|---|
| 9 | #include "perandom.h"
 | 
|---|
| 10 | 
 | 
|---|
| 11 | #include "FFTW/fftw3.h"
 | 
|---|
| 12 | #include "FitsIO/fitsio.h"
 | 
|---|
| 13 | 
 | 
|---|
| 14 | #include <vector>
 | 
|---|
| 15 | 
 | 
|---|
| 16 | #include "cosmocalc.h"
 | 
|---|
| 17 | #include "pkspectrum.h"
 | 
|---|
| 18 | 
 | 
|---|
| 19 | 
 | 
|---|
| 20 | namespace SOPHYA {
 | 
|---|
| 21 | 
 | 
|---|
| 22 | //-----------------------------------------------------------------------------------
 | 
|---|
| 23 | class GeneFluct3D {
 | 
|---|
| 24 | public:
 | 
|---|
| 25 |   GeneFluct3D(TArray< complex<r_8 > >& T);
 | 
|---|
| 26 |   virtual ~GeneFluct3D(void);
 | 
|---|
| 27 | 
 | 
|---|
| 28 |   void SetNThread(unsigned short nthread=0) {nthread_ = nthread;}
 | 
|---|
| 29 |   void SetSize(long nx,long ny,long nz,double dx,double dy,double dz);  // Mpc
 | 
|---|
| 30 |   void SetObservator(double redshref=0.,double kredshref=0.);
 | 
|---|
| 31 |   void SetCosmology(CosmoCalc& cosmo);
 | 
|---|
| 32 |   void SetGrowthFactor(GrowthFactor& growth);
 | 
|---|
| 33 |   long LosComRedshift(double zinc=0.001);
 | 
|---|
| 34 | 
 | 
|---|
| 35 |   TArray< complex<r_8> >& GetComplexArray(void) {return T_;}
 | 
|---|
| 36 |   fftw_complex* GetComplexPointer(void) {return fdata_;}
 | 
|---|
| 37 |   TArray<r_8>& GetRealArray(void) {return R_;}
 | 
|---|
| 38 |   r_8* GetRealPointer(void) {return data_;}
 | 
|---|
| 39 | 
 | 
|---|
| 40 |   // Pour adressage data_[ip]
 | 
|---|
| 41 |   inline int_8 IndexR(long i,long j,long k) {return (int_8)(k+NTz_*(j+Ny_*i));}
 | 
|---|
| 42 |   // Pour adressage fdata_[ip][0-1]
 | 
|---|
| 43 |   inline int_8 IndexC(long i,long j,long k) {return (int_8)(k+NCz_*(j+Ny_*i));}
 | 
|---|
| 44 |   // - On peut aussi adresser:
 | 
|---|
| 45 |   // TArray< complex<r_8> >& pk = gf3d.GetComplexArray(); pk(i,j,k) = ...;
 | 
|---|
| 46 |   // TArray<r_8>& rgen = gf3d.GetRealArray(); rgen(i,j,k) = ...;
 | 
|---|
| 47 | 
 | 
|---|
| 48 |   vector<long> GetNpix(void) {return N_;}
 | 
|---|
| 49 |   int_8 NPix(void) {return NRtot_;}
 | 
|---|
| 50 | 
 | 
|---|
| 51 |   vector<r_8> GetDinc(void) {return D_;}
 | 
|---|
| 52 |   double GetDVol(void) {return dVol_;}
 | 
|---|
| 53 |   double GetVol(void) {return Vol_;}
 | 
|---|
| 54 | 
 | 
|---|
| 55 |   vector<r_8> GetKinc(void) {return Dk_;}
 | 
|---|
| 56 |   vector<r_8> GetKnyq(void) {return Knyq_;}
 | 
|---|
| 57 |   double GetKmax(void) {return sqrt(Knyqx_*Knyqx_+Knyqy_*Knyqy_+Knyqz_*Knyqz_);}
 | 
|---|
| 58 |   double GetKTmax(void) {return sqrt(Knyqx_*Knyqx_+Knyqy_*Knyqy_);}
 | 
|---|
| 59 |   double GetKincMin(void)
 | 
|---|
| 60 |     {vector<r_8>::const_iterator it = min_element(Dk_.begin(), Dk_.end()); return *it;}
 | 
|---|
| 61 |   double GetKTincMin(void) {return min(Dk_[0],Dk_[1]);}
 | 
|---|
| 62 | 
 | 
|---|
| 63 |   void ComputeFourier0(GenericFunc& pk_at_z);
 | 
|---|
| 64 |   void ComputeFourier(GenericFunc& pk_at_z);
 | 
|---|
| 65 |   void FilterByPixel(void);
 | 
|---|
| 66 | 
 | 
|---|
| 67 |   void ComputeReal(void);
 | 
|---|
| 68 | 
 | 
|---|
| 69 |   void ReComputeFourier(void);
 | 
|---|
| 70 | 
 | 
|---|
| 71 |   int  ComputeSpectrum(HistoErr& herr);
 | 
|---|
| 72 |   int  ComputeSpectrum2D(Histo2DErr& herr);
 | 
|---|
| 73 |   void ApplyGrowthFactor(long npoints=-1);
 | 
|---|
| 74 | 
 | 
|---|
| 75 |   int_8 VarianceFrReal(double R,double& var);
 | 
|---|
| 76 |   int_8 MeanSigma2(double& rm,double& rs2,double vmin=-1.e+150,double vmax=1.e+150);
 | 
|---|
| 77 |   int_8 NumberOfBad(double vmin=-1.e+150,double vmax=1.e+150);
 | 
|---|
| 78 |   int_8 SetToVal(double vmin, double vmax,double val0=0.);
 | 
|---|
| 79 | 
 | 
|---|
| 80 |   void TurnFluct2Mass(void);
 | 
|---|
| 81 |   double TurnMass2MeanNumber(double n_by_mpc3);
 | 
|---|
| 82 |   double ApplyPoisson(void);
 | 
|---|
| 83 |   double TurnNGal2Mass(FunRan& massdist,bool axeslog=false);
 | 
|---|
| 84 |   double TurnMass2Flux(void);
 | 
|---|
| 85 |   void AddNoise2Real(double snoise);
 | 
|---|
| 86 | 
 | 
|---|
| 87 |   void WriteFits(string cfname,int bitpix=FLOAT_IMG);
 | 
|---|
| 88 |   void ReadFits(string cfname);
 | 
|---|
| 89 | 
 | 
|---|
| 90 |   void WritePPF(string cfname,bool write_real=true);
 | 
|---|
| 91 |   void ReadPPF(string cfname);
 | 
|---|
| 92 | 
 | 
|---|
| 93 |   void SetPrtLevel(int lp=0) {lp_ = lp;}
 | 
|---|
| 94 |   void Print(void);
 | 
|---|
| 95 | 
 | 
|---|
| 96 | protected:
 | 
|---|
| 97 |   void setsize(long nx,long ny,long nz,double dx,double dy,double dz);
 | 
|---|
| 98 |   void setalloc(void);
 | 
|---|
| 99 |   void setpointers(bool from_real);
 | 
|---|
| 100 |   void init_fftw(void);
 | 
|---|
| 101 |   long manage_coefficients(void);
 | 
|---|
| 102 |   double compute_power_carte(void);
 | 
|---|
| 103 |   void check_array_alloc(void);
 | 
|---|
| 104 |   inline double pixelfilter(double x)
 | 
|---|
| 105 |     {return (x<0.025) ? 1.-x*x/6.*(1.-x*x/20.): sin(x)/x;}
 | 
|---|
| 106 | 
 | 
|---|
| 107 |   // valeurs dans l'espace reel
 | 
|---|
| 108 |   long Nx_,Ny_,Nz_;  vector<long> N_;
 | 
|---|
| 109 |   long NCz_,NTz_;
 | 
|---|
| 110 |   int_8 NRtot_;
 | 
|---|
| 111 | 
 | 
|---|
| 112 |   double Dx_,Dy_,Dz_;  vector<double> D_;
 | 
|---|
| 113 | 
 | 
|---|
| 114 |   // valeurs dans l'espace des K
 | 
|---|
| 115 |   double Dkx_,Dky_,Dkz_;  vector<double> Dk_;
 | 
|---|
| 116 |   double Knyqx_,Knyqy_,Knyqz_;  vector<double> Knyq_;
 | 
|---|
| 117 |   double Dk3_;
 | 
|---|
| 118 |   double dVol_, Vol_;
 | 
|---|
| 119 | 
 | 
|---|
| 120 |   // la gestion de la FFT
 | 
|---|
| 121 |   fftw_plan pf_,pb_;
 | 
|---|
| 122 |   unsigned short nthread_;
 | 
|---|
| 123 |   int lp_;
 | 
|---|
| 124 | 
 | 
|---|
| 125 |   // le stockage du Cube de donnees et les pointeurs
 | 
|---|
| 126 |   bool array_allocated_;  // true if array has been allocated
 | 
|---|
| 127 |   TArray< complex<r_8> >& T_;
 | 
|---|
| 128 |   fftw_complex *fdata_;
 | 
|---|
| 129 |   TArray<r_8> R_;
 | 
|---|
| 130 |   double *data_;
 | 
|---|
| 131 | 
 | 
|---|
| 132 |   // l'observateur
 | 
|---|
| 133 |   double redshref_,kredshref_;
 | 
|---|
| 134 |   CosmoCalc *cosmo_;
 | 
|---|
| 135 |   GrowthFactor *growth_;
 | 
|---|
| 136 |   double xobs_[3];
 | 
|---|
| 137 |   double loscom_ref_, loscom_min_, loscom_max_;
 | 
|---|
| 138 |   vector<double> zred_, loscom_;
 | 
|---|
| 139 | };
 | 
|---|
| 140 | 
 | 
|---|
| 141 | } // Fin du namespace
 | 
|---|
| 142 | 
 | 
|---|
| 143 | #endif
 | 
|---|