source: Sophya/trunk/Cosmo/SimLSS/genefluct3d.h@ 3518

Last change on this file since 3518 was 3518, checked in by cmv, 17 years ago

possibilite de travailler en float cmv 11/09/2008

File size: 6.4 KB
Line 
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#define WITH_FFTW_THREAD
21//#define GEN3D_FLOAT
22
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
33namespace SOPHYA {
34
35//-----------------------------------------------------------------------------------
36class GeneFluct3D {
37public:
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);
40 virtual ~GeneFluct3D(void);
41
42 // Distance los comobile a l'observateur
43 void SetObservator(double redshref=0.,double kredshref=0.);
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 }
51 void SetCosmology(CosmoCalc& cosmo);
52 void SetGrowthFactor(GrowthFactor& growth);
53 long LosComRedshift(double zinc=0.001,long npoints=-1);
54
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_;}
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));}
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]
74
75 vector<long> GetNpix(void) {return N_;}
76 int_8 NPix(void) {return NRtot_;}
77 long GetNx(void) {return Nx_;}
78 long GetNy(void) {return Ny_;}
79 long GetNz(void) {return Nz_;}
80
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
86 vector<r_8> GetDinc(void) {return D_;}
87 double GetDVol(void) {return dVol_;}
88 double GetVol(void) {return Vol_;}
89
90 vector<r_8> GetKinc(void) {return Dk_;}
91 vector<r_8> GetKnyq(void) {return Knyq_;}
92 double GetKmax(void) {return sqrt(Knyqx_*Knyqx_+Knyqy_*Knyqy_+Knyqz_*Knyqz_);}
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;}
96 double GetKincMax(void)
97 {vector<r_8>::const_iterator it = max_element(Dk_.begin(), Dk_.end()); return *it;}
98 double GetKTincMin(void) {return min(Dk_[0],Dk_[1]);}
99 double GetKTincMax(void) {return max(Dk_[0],Dk_[1]);}
100
101 void ComputeFourier0(GenericFunc& pk_at_z);
102 void ComputeFourier(GenericFunc& pk_at_z);
103 void FilterByPixel(void);
104
105 void ComputeReal(void);
106 void ApplyGrowthFactor(int type_evol=1);
107
108 void ReComputeFourier(void);
109
110 int ComputeSpectrum(HistoErr& herr);
111 int ComputeSpectrum2D(Histo2DErr& herr);
112 int ComputeSpectrum(HistoErr& herr,double sigma,bool pixcor);
113 int ComputeSpectrum2D(Histo2DErr& herr,double sigma,bool pixcor);
114
115 int_8 VarianceFrReal(double R,double& var);
116 int_8 MeanSigma2(double& rm,double& rs2,double vmin=1.,double vmax=-1.
117 ,bool useout=false,double vout=0.);
118 int_8 MinMax(double& xmin,double& xmax,double vmin=1.,double vmax=-1.);
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.);
121 void ScaleOffset(double scalecube=1.,double offsetcube=0.);
122
123 void TurnFluct2Mass(void);
124 double TurnFluct2MeanNumber(double val_by_mpc3);
125 double ApplyPoisson(void);
126 double TurnNGal2Mass(FunRan& massdist,bool axeslog=false);
127 double TurnNGal2MassQuick(SchechterMassDist& schmdist);
128 double TurnMass2Flux(void);
129 //void AddAGN(double lfjy,double lsigma,double powlaw=0.);
130 void AddNoise2Real(double snoise,int type_evol=0);
131
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);
137 void WriteSlicePPF(string cfname);
138
139 void SetPrtLevel(int lp=0) {lp_ = lp;}
140 void Print(void);
141
142//-------------------------------------------------------------------
143
144protected:
145 void init_default(void);
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);
149 void init_fftw(void);
150 void delete_fftw(void);
151 long manage_coefficients(void);
152 double compute_power_carte(void);
153 void check_array_alloc(void);
154 inline double pixelfilter(double x)
155 {return (x<0.025) ? 1.-x*x/6.*(1.-x*x/20.): sin(x)/x;}
156
157 // valeurs dans l'espace reel
158 long Nx_,Ny_,Nz_; vector<long> N_;
159 long NCz_,NTz_;
160 int_8 NRtot_;
161
162 double Dx_,Dy_,Dz_; vector<double> D_;
163
164 // valeurs dans l'espace des K
165 double Dkx_,Dky_,Dkz_; vector<double> Dk_;
166 double Knyqx_,Knyqy_,Knyqz_; vector<double> Knyq_;
167 double Dk3_;
168 double dVol_, Vol_;
169
170 // la gestion de la FFT
171 bool is_set_fft_plan;
172 GEN3D_FFTW_PLAN pf_,pb_;
173 unsigned short nthread_;
174 int lp_;
175
176 // le stockage du Cube de donnees et les pointeurs
177 bool array_allocated_; // true if array has been allocated
178 TArray< complex<GEN3D_TYPE> > T_;
179 GEN3D_FFTW_COMPLEX *fdata_;
180 TArray<GEN3D_TYPE> R_;
181 GEN3D_TYPE *data_;
182
183 // l'observateur
184 CosmoCalc *cosmo_;
185 GrowthFactor *growth_;
186 double redsh_ref_,kredsh_ref_,dred_ref_;
187 double loscom_ref_,dtrc_ref_, dlum_ref_, dang_ref_;
188 double nu_ref_, dnu_ref_ ;
189 double xobs_[3];
190 double loscom_min_, loscom_max_;
191 vector<double> zred_, loscom_;
192 double loscom2zred_min_, loscom2zred_max_;
193 vector<double> loscom2zred_;
194
195};
196
197} // Fin du namespace SOPHYA
198
199#endif
Note: See TracBrowser for help on using the repository browser.