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

Last change on this file since 3329 was 3329, checked in by cmv, 18 years ago

possibilite de ne pas faire poisson sur Ngal cmv 27/09/2007

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