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

Last change on this file since 3756 was 3662, checked in by cmv, 16 years ago

suggest explicit braces to avoid ambiguous else g++ warning corrected, cmv 23/10/2009

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