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