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

Last change on this file since 3768 was 3768, checked in by cmv, 15 years ago
  • refonte du code pour creer uniquement des conditions initiales
  • introduction du tirage des vitesse LOS pour les redshift-distortion

cmv 03/05/2010

File size: 7.3 KB
RevLine 
[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>
[3619]16#include <algorithm>
[3115]17
[3157]18#include "cosmocalc.h"
[3115]19#include "pkspectrum.h"
[3768]20#include "schechter.h"
[3115]21
[3518]22#define WITH_FFTW_THREAD
[3115]23
[3768]24//NE PAS DECOMMENTER, UTILISEZ LA MAKEFILE ("g++ -DGEN3D_FLOAT ...")
[3518]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
[3115]35namespace SOPHYA {
36
37//-----------------------------------------------------------------------------------
38class GeneFluct3D {
39public:
[3349]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);
[3115]42 virtual ~GeneFluct3D(void);
43
[3271]44 // Distance los comobile a l'observateur
[3157]45 void SetObservator(double redshref=0.,double kredshref=0.);
[3271]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 }
[3157]53 void SetCosmology(CosmoCalc& cosmo);
54 void SetGrowthFactor(GrowthFactor& growth);
[3199]55 long LosComRedshift(double zinc=0.001,long npoints=-1);
[3115]56
[3518]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_;}
[3141]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));}
[3330]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]
[3141]76
77 vector<long> GetNpix(void) {return N_;}
78 int_8 NPix(void) {return NRtot_;}
[3768]79 long Nx(void) {return Nx_;}
80 long Ny(void) {return Ny_;}
81 long Nz(void) {return Nz_;}
82 double Dx(void) {return Dx_;}
83 double Dy(void) {return Dy_;}
84 double Dz(void) {return Dz_;}
[3141]85
[3290]86 // Return |K_i| module relative to pixel indices
87 inline r_8 Kx(long i) {long ii=(i>Nx_/2)? Nx_-i :i; return ii*Dkx_;}
88 inline r_8 Ky(long j) {long jj=(j>Ny_/2)? Ny_-j :j; return jj*Dky_;}
89 inline r_8 Kz(long l) {return l*Dkz_;}
90
[3141]91 vector<r_8> GetDinc(void) {return D_;}
92 double GetDVol(void) {return dVol_;}
[3115]93 double GetVol(void) {return Vol_;}
[3141]94
95 vector<r_8> GetKinc(void) {return Dk_;}
96 vector<r_8> GetKnyq(void) {return Knyq_;}
[3115]97 double GetKmax(void) {return sqrt(Knyqx_*Knyqx_+Knyqy_*Knyqy_+Knyqz_*Knyqz_);}
[3141]98 double GetKTmax(void) {return sqrt(Knyqx_*Knyqx_+Knyqy_*Knyqy_);}
99 double GetKincMin(void)
100 {vector<r_8>::const_iterator it = min_element(Dk_.begin(), Dk_.end()); return *it;}
[3289]101 double GetKincMax(void)
102 {vector<r_8>::const_iterator it = max_element(Dk_.begin(), Dk_.end()); return *it;}
[3141]103 double GetKTincMin(void) {return min(Dk_[0],Dk_[1]);}
[3289]104 double GetKTincMax(void) {return max(Dk_[0],Dk_[1]);}
[3115]105
[3768]106 double Zref(void) {return redsh_ref_;}
107 double ZrefPk(void) {return compute_pk_redsh_ref_;}
108 double Dref(void) {return growth_ref_;}
109 double DrefPk(void)
110 {return (growth_!=NULL && compute_pk_redsh_ref_>=0.) ? (*growth_)(compute_pk_redsh_ref_): -999.;}
111
112 void ComputeFourier0(PkSpectrumZ& pk_at_z);
113 void ComputeFourier(PkSpectrumZ& pk_at_z);
[3115]114 void FilterByPixel(void);
[3768]115 void ToVelTrans(void);
[3141]116
[3115]117 void ComputeReal(void);
[3331]118 void ApplyGrowthFactor(int type_evol=1);
[3768]119 void ApplyDerGrowthFactor(int type_evol=1);
[3141]120
[3115]121 void ReComputeFourier(void);
122
[3141]123 int ComputeSpectrum(HistoErr& herr);
124 int ComputeSpectrum2D(Histo2DErr& herr);
[3330]125 int ComputeSpectrum(HistoErr& herr,double sigma,bool pixcor);
126 int ComputeSpectrum2D(Histo2DErr& herr,double sigma,bool pixcor);
[3141]127
[3134]128 int_8 VarianceFrReal(double R,double& var);
[3261]129 int_8 MeanSigma2(double& rm,double& rs2,double vmin=1.,double vmax=-1.
130 ,bool useout=false,double vout=0.);
[3320]131 int_8 MinMax(double& xmin,double& xmax,double vmin=1.,double vmax=-1.);
[3134]132 int_8 NumberOfBad(double vmin=-1.e+150,double vmax=1.e+150);
133 int_8 SetToVal(double vmin, double vmax,double val0=0.);
[3283]134 void ScaleOffset(double scalecube=1.,double offsetcube=0.);
[3115]135
136 void TurnFluct2Mass(void);
[3358]137 double TurnFluct2MeanNumber(double val_by_mpc3);
[3115]138 double ApplyPoisson(void);
139 double TurnNGal2Mass(FunRan& massdist,bool axeslog=false);
[3320]140 double TurnNGal2MassQuick(SchechterMassDist& schmdist);
[3115]141 double TurnMass2Flux(void);
[3349]142 //void AddAGN(double lfjy,double lsigma,double powlaw=0.);
[3331]143 void AddNoise2Real(double snoise,int type_evol=0);
[3115]144
[3141]145 void WriteFits(string cfname,int bitpix=FLOAT_IMG);
146 void ReadFits(string cfname);
147
148 void WritePPF(string cfname,bool write_real=true);
149 void ReadPPF(string cfname);
[3281]150 void WriteSlicePPF(string cfname);
[3524]151 void NTupleCheck(POutPersist &pos,string ntname,unsigned long nent);
[3141]152
[3150]153 void SetPrtLevel(int lp=0) {lp_ = lp;}
[3115]154 void Print(void);
155
[3199]156//-------------------------------------------------------------------
157
[3115]158protected:
[3349]159 void init_default(void);
[3141]160 void setsize(long nx,long ny,long nz,double dx,double dy,double dz);
161 void setalloc(void);
162 void setpointers(bool from_real);
[3154]163 void init_fftw(void);
[3349]164 void delete_fftw(void);
[3129]165 long manage_coefficients(void);
[3115]166 double compute_power_carte(void);
[3141]167 void check_array_alloc(void);
[3662]168 inline double pixelfilter(double x) // ATTENTION: seulement pour x>0
[3120]169 {return (x<0.025) ? 1.-x*x/6.*(1.-x*x/20.): sin(x)/x;}
[3115]170
[3154]171 // valeurs dans l'espace reel
[3141]172 long Nx_,Ny_,Nz_; vector<long> N_;
[3129]173 long NCz_,NTz_;
[3134]174 int_8 NRtot_;
[3141]175
176 double Dx_,Dy_,Dz_; vector<double> D_;
177
[3154]178 // valeurs dans l'espace des K
[3141]179 double Dkx_,Dky_,Dkz_; vector<double> Dk_;
180 double Knyqx_,Knyqy_,Knyqz_; vector<double> Knyq_;
181 double Dk3_;
[3115]182 double dVol_, Vol_;
183
[3154]184 // la gestion de la FFT
[3518]185 bool is_set_fft_plan;
186 GEN3D_FFTW_PLAN pf_,pb_;
[3115]187 unsigned short nthread_;
[3150]188 int lp_;
[3115]189
[3154]190 // le stockage du Cube de donnees et les pointeurs
[3141]191 bool array_allocated_; // true if array has been allocated
[3524]192 unsigned short array_type; // 0=empty, 1=real, 2=complex
[3518]193 TArray< complex<GEN3D_TYPE> > T_;
194 GEN3D_FFTW_COMPLEX *fdata_;
195 TArray<GEN3D_TYPE> R_;
196 GEN3D_TYPE *data_;
[3154]197
198 // l'observateur
[3157]199 CosmoCalc *cosmo_;
200 GrowthFactor *growth_;
[3768]201 double good_dzinc_;
[3271]202 double redsh_ref_,kredsh_ref_,dred_ref_;
[3768]203 double compute_pk_redsh_ref_;
204 double h_ref, loscom_ref_,dtrc_ref_, dlum_ref_, dang_ref_;
205 double growth_ref_, dsdz_growth_ref_;
[3271]206 double nu_ref_, dnu_ref_ ;
[3157]207 double xobs_[3];
[3768]208
[3271]209 double loscom_min_, loscom_max_;
[3157]210 vector<double> zred_, loscom_;
[3199]211 double loscom2zred_min_, loscom2zred_max_;
212 vector<double> loscom2zred_;
213
[3768]214 double zredmin_dpsd_, zredmax_dpsd_;
215 vector<double> dpsdfrzred_;
216
[3115]217};
218
[3325]219} // Fin du namespace SOPHYA
[3115]220
221#endif
Note: See TracBrowser for help on using the repository browser.