[3115] | 1 | #ifndef GENEFLUCT3D_SEEN
|
---|
| 2 | #define GENEFLUCT3D_SEEN
|
---|
| 3 |
|
---|
| 4 | #include "machdefs.h"
|
---|
[3289] | 5 | #include <math.h>
|
---|
[3115] | 6 | #include "genericfunc.h"
|
---|
| 7 | #include "tarray.h"
|
---|
[3141] | 8 | #include "histerr.h"
|
---|
| 9 | #include "hist2err.h"
|
---|
[3115] | 10 | #include "perandom.h"
|
---|
| 11 |
|
---|
[3141] | 12 | #include "FFTW/fftw3.h"
|
---|
| 13 | #include "FitsIO/fitsio.h"
|
---|
| 14 |
|
---|
[3115] | 15 | #include <vector>
|
---|
| 16 |
|
---|
[3157] | 17 | #include "cosmocalc.h"
|
---|
[3115] | 18 | #include "pkspectrum.h"
|
---|
| 19 |
|
---|
[3518] | 20 | #define WITH_FFTW_THREAD
|
---|
| 21 | //#define GEN3D_FLOAT
|
---|
[3115] | 22 |
|
---|
[3518] | 23 | #if defined(GEN3D_FLOAT)
|
---|
| 24 | #define GEN3D_TYPE r_4
|
---|
| 25 | #define GEN3D_FFTW_PLAN fftwf_plan
|
---|
| 26 | #define GEN3D_FFTW_COMPLEX fftwf_complex
|
---|
| 27 | #else
|
---|
| 28 | #define GEN3D_TYPE r_8
|
---|
| 29 | #define GEN3D_FFTW_PLAN fftw_plan
|
---|
| 30 | #define GEN3D_FFTW_COMPLEX fftw_complex
|
---|
| 31 | #endif
|
---|
| 32 |
|
---|
[3115] | 33 | namespace SOPHYA {
|
---|
| 34 |
|
---|
| 35 | //-----------------------------------------------------------------------------------
|
---|
| 36 | class GeneFluct3D {
|
---|
| 37 | public:
|
---|
[3349] | 38 | GeneFluct3D(long nx,long ny,long nz,double dx,double dy,double dz,unsigned short nthread=0,int lp=0); // Mpc
|
---|
| 39 | GeneFluct3D(unsigned short nthread=0);
|
---|
[3115] | 40 | virtual ~GeneFluct3D(void);
|
---|
| 41 |
|
---|
[3271] | 42 | // Distance los comobile a l'observateur
|
---|
[3157] | 43 | void SetObservator(double redshref=0.,double kredshref=0.);
|
---|
[3271] | 44 | inline double DXcom(long i) {return i*Dx_ - xobs_[0];}
|
---|
| 45 | inline double DYcom(long j) {return j*Dy_ - xobs_[1];}
|
---|
| 46 | inline double DZcom(long k) {return k*Dz_ - xobs_[2];}
|
---|
| 47 | inline double Dcom(long i,long j,long k) {
|
---|
| 48 | double dx=DXcom(i), dy=DYcom(j), dz=DZcom(k);
|
---|
| 49 | return sqrt(dx*dx+dy*dy+dz*dz);
|
---|
| 50 | }
|
---|
[3157] | 51 | void SetCosmology(CosmoCalc& cosmo);
|
---|
| 52 | void SetGrowthFactor(GrowthFactor& growth);
|
---|
[3199] | 53 | long LosComRedshift(double zinc=0.001,long npoints=-1);
|
---|
[3115] | 54 |
|
---|
[3518] | 55 | TArray< complex<GEN3D_TYPE> >& GetComplexArray(void) {return T_;}
|
---|
| 56 | GEN3D_FFTW_COMPLEX * GetComplexPointer(void) {return fdata_;}
|
---|
| 57 | TArray<GEN3D_TYPE>& GetRealArray(void) {return R_;}
|
---|
| 58 | GEN3D_TYPE* GetRealPointer(void) {return data_;}
|
---|
[3141] | 59 |
|
---|
| 60 | // Pour adressage data_[ip]
|
---|
| 61 | inline int_8 IndexR(long i,long j,long k) {return (int_8)(k+NTz_*(j+Ny_*i));}
|
---|
| 62 | // Pour adressage fdata_[ip][0-1]
|
---|
| 63 | inline int_8 IndexC(long i,long j,long k) {return (int_8)(k+NCz_*(j+Ny_*i));}
|
---|
[3330] | 64 | // On peut aussi adresser:
|
---|
| 65 | // TArray< complex<r_8> >& pk = gf3d.GetComplexArray();
|
---|
| 66 | // pk(k,j,i) avec k=[0,NCz_[ j=[0,Ny_[ i=[0,Nx_[
|
---|
| 67 | // pk[IndexC(i,j,k)]
|
---|
| 68 | // TArray<r_8>& rgen = gf3d.GetRealArray();
|
---|
| 69 | // rgen(k,j,i) avec k=[0,NTz_[ j=[0,Ny_[ i=[0,Nx_[
|
---|
| 70 | // mais seul k=[0,Nz_[ est utile
|
---|
| 71 | // rgen[IndexR(i,j,k)]
|
---|
| 72 | // ATTENTION: TArray adresse en memoire a l'envers du C !
|
---|
| 73 | // Tarray(n1,n2,n3) == Carray[n3][n2][n1]
|
---|
[3141] | 74 |
|
---|
| 75 | vector<long> GetNpix(void) {return N_;}
|
---|
| 76 | int_8 NPix(void) {return NRtot_;}
|
---|
[3330] | 77 | long GetNx(void) {return Nx_;}
|
---|
| 78 | long GetNy(void) {return Ny_;}
|
---|
| 79 | long GetNz(void) {return Nz_;}
|
---|
[3141] | 80 |
|
---|
[3290] | 81 | // Return |K_i| module relative to pixel indices
|
---|
| 82 | inline r_8 Kx(long i) {long ii=(i>Nx_/2)? Nx_-i :i; return ii*Dkx_;}
|
---|
| 83 | inline r_8 Ky(long j) {long jj=(j>Ny_/2)? Ny_-j :j; return jj*Dky_;}
|
---|
| 84 | inline r_8 Kz(long l) {return l*Dkz_;}
|
---|
| 85 |
|
---|
[3141] | 86 | vector<r_8> GetDinc(void) {return D_;}
|
---|
| 87 | double GetDVol(void) {return dVol_;}
|
---|
[3115] | 88 | double GetVol(void) {return Vol_;}
|
---|
[3141] | 89 |
|
---|
| 90 | vector<r_8> GetKinc(void) {return Dk_;}
|
---|
| 91 | vector<r_8> GetKnyq(void) {return Knyq_;}
|
---|
[3115] | 92 | double GetKmax(void) {return sqrt(Knyqx_*Knyqx_+Knyqy_*Knyqy_+Knyqz_*Knyqz_);}
|
---|
[3141] | 93 | double GetKTmax(void) {return sqrt(Knyqx_*Knyqx_+Knyqy_*Knyqy_);}
|
---|
| 94 | double GetKincMin(void)
|
---|
| 95 | {vector<r_8>::const_iterator it = min_element(Dk_.begin(), Dk_.end()); return *it;}
|
---|
[3289] | 96 | double GetKincMax(void)
|
---|
| 97 | {vector<r_8>::const_iterator it = max_element(Dk_.begin(), Dk_.end()); return *it;}
|
---|
[3141] | 98 | double GetKTincMin(void) {return min(Dk_[0],Dk_[1]);}
|
---|
[3289] | 99 | double GetKTincMax(void) {return max(Dk_[0],Dk_[1]);}
|
---|
[3115] | 100 |
|
---|
[3141] | 101 | void ComputeFourier0(GenericFunc& pk_at_z);
|
---|
| 102 | void ComputeFourier(GenericFunc& pk_at_z);
|
---|
[3115] | 103 | void FilterByPixel(void);
|
---|
[3141] | 104 |
|
---|
[3115] | 105 | void ComputeReal(void);
|
---|
[3331] | 106 | void ApplyGrowthFactor(int type_evol=1);
|
---|
[3141] | 107 |
|
---|
[3115] | 108 | void ReComputeFourier(void);
|
---|
| 109 |
|
---|
[3141] | 110 | int ComputeSpectrum(HistoErr& herr);
|
---|
| 111 | int ComputeSpectrum2D(Histo2DErr& herr);
|
---|
[3330] | 112 | int ComputeSpectrum(HistoErr& herr,double sigma,bool pixcor);
|
---|
| 113 | int ComputeSpectrum2D(Histo2DErr& herr,double sigma,bool pixcor);
|
---|
[3141] | 114 |
|
---|
[3134] | 115 | int_8 VarianceFrReal(double R,double& var);
|
---|
[3261] | 116 | int_8 MeanSigma2(double& rm,double& rs2,double vmin=1.,double vmax=-1.
|
---|
| 117 | ,bool useout=false,double vout=0.);
|
---|
[3320] | 118 | int_8 MinMax(double& xmin,double& xmax,double vmin=1.,double vmax=-1.);
|
---|
[3134] | 119 | int_8 NumberOfBad(double vmin=-1.e+150,double vmax=1.e+150);
|
---|
| 120 | int_8 SetToVal(double vmin, double vmax,double val0=0.);
|
---|
[3283] | 121 | void ScaleOffset(double scalecube=1.,double offsetcube=0.);
|
---|
[3115] | 122 |
|
---|
| 123 | void TurnFluct2Mass(void);
|
---|
[3358] | 124 | double TurnFluct2MeanNumber(double val_by_mpc3);
|
---|
[3115] | 125 | double ApplyPoisson(void);
|
---|
| 126 | double TurnNGal2Mass(FunRan& massdist,bool axeslog=false);
|
---|
[3320] | 127 | double TurnNGal2MassQuick(SchechterMassDist& schmdist);
|
---|
[3115] | 128 | double TurnMass2Flux(void);
|
---|
[3349] | 129 | //void AddAGN(double lfjy,double lsigma,double powlaw=0.);
|
---|
[3331] | 130 | void AddNoise2Real(double snoise,int type_evol=0);
|
---|
[3115] | 131 |
|
---|
[3141] | 132 | void WriteFits(string cfname,int bitpix=FLOAT_IMG);
|
---|
| 133 | void ReadFits(string cfname);
|
---|
| 134 |
|
---|
| 135 | void WritePPF(string cfname,bool write_real=true);
|
---|
| 136 | void ReadPPF(string cfname);
|
---|
[3281] | 137 | void WriteSlicePPF(string cfname);
|
---|
[3141] | 138 |
|
---|
[3150] | 139 | void SetPrtLevel(int lp=0) {lp_ = lp;}
|
---|
[3115] | 140 | void Print(void);
|
---|
| 141 |
|
---|
[3199] | 142 | //-------------------------------------------------------------------
|
---|
| 143 |
|
---|
[3115] | 144 | protected:
|
---|
[3349] | 145 | void init_default(void);
|
---|
[3141] | 146 | void setsize(long nx,long ny,long nz,double dx,double dy,double dz);
|
---|
| 147 | void setalloc(void);
|
---|
| 148 | void setpointers(bool from_real);
|
---|
[3154] | 149 | void init_fftw(void);
|
---|
[3349] | 150 | void delete_fftw(void);
|
---|
[3129] | 151 | long manage_coefficients(void);
|
---|
[3115] | 152 | double compute_power_carte(void);
|
---|
[3141] | 153 | void check_array_alloc(void);
|
---|
[3120] | 154 | inline double pixelfilter(double x)
|
---|
| 155 | {return (x<0.025) ? 1.-x*x/6.*(1.-x*x/20.): sin(x)/x;}
|
---|
[3115] | 156 |
|
---|
[3154] | 157 | // valeurs dans l'espace reel
|
---|
[3141] | 158 | long Nx_,Ny_,Nz_; vector<long> N_;
|
---|
[3129] | 159 | long NCz_,NTz_;
|
---|
[3134] | 160 | int_8 NRtot_;
|
---|
[3141] | 161 |
|
---|
| 162 | double Dx_,Dy_,Dz_; vector<double> D_;
|
---|
| 163 |
|
---|
[3154] | 164 | // valeurs dans l'espace des K
|
---|
[3141] | 165 | double Dkx_,Dky_,Dkz_; vector<double> Dk_;
|
---|
| 166 | double Knyqx_,Knyqy_,Knyqz_; vector<double> Knyq_;
|
---|
| 167 | double Dk3_;
|
---|
[3115] | 168 | double dVol_, Vol_;
|
---|
| 169 |
|
---|
[3154] | 170 | // la gestion de la FFT
|
---|
[3518] | 171 | bool is_set_fft_plan;
|
---|
| 172 | GEN3D_FFTW_PLAN pf_,pb_;
|
---|
[3115] | 173 | unsigned short nthread_;
|
---|
[3150] | 174 | int lp_;
|
---|
[3115] | 175 |
|
---|
[3154] | 176 | // le stockage du Cube de donnees et les pointeurs
|
---|
[3141] | 177 | bool array_allocated_; // true if array has been allocated
|
---|
[3518] | 178 | TArray< complex<GEN3D_TYPE> > T_;
|
---|
| 179 | GEN3D_FFTW_COMPLEX *fdata_;
|
---|
| 180 | TArray<GEN3D_TYPE> R_;
|
---|
| 181 | GEN3D_TYPE *data_;
|
---|
[3154] | 182 |
|
---|
| 183 | // l'observateur
|
---|
[3157] | 184 | CosmoCalc *cosmo_;
|
---|
| 185 | GrowthFactor *growth_;
|
---|
[3271] | 186 | double redsh_ref_,kredsh_ref_,dred_ref_;
|
---|
| 187 | double loscom_ref_,dtrc_ref_, dlum_ref_, dang_ref_;
|
---|
| 188 | double nu_ref_, dnu_ref_ ;
|
---|
[3157] | 189 | double xobs_[3];
|
---|
[3271] | 190 | double loscom_min_, loscom_max_;
|
---|
[3157] | 191 | vector<double> zred_, loscom_;
|
---|
[3199] | 192 | double loscom2zred_min_, loscom2zred_max_;
|
---|
| 193 | vector<double> loscom2zred_;
|
---|
| 194 |
|
---|
[3115] | 195 | };
|
---|
| 196 |
|
---|
[3325] | 197 | } // Fin du namespace SOPHYA
|
---|
[3115] | 198 |
|
---|
| 199 | #endif
|
---|