Changeset 3141 in Sophya for trunk/Cosmo


Ignore:
Timestamp:
Jan 17, 2007, 6:44:04 PM (19 years ago)
Author:
cmv
Message:

chgt HProf->HistoErr + spectre 2D cmv 17/01/2007

Location:
trunk/Cosmo/SimLSS
Files:
1 added
1 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Cosmo/SimLSS/Makefile

    r3120 r3141  
    1919       $(EXE)cmvtstsch $(EXE)cmvtstblack $(EXE)cmvtvarspec \
    2020       $(EXE)cmvdefsurv $(EXE)cmvobserv3d $(EXE)cmvtintfun \
    21        $(EXE)cmvtpoisson $(EXE)cmvconchprof
     21       $(EXE)cmvtpoisson $(EXE)cmvconcherr
    2222#$(EXE)cmvtluc
    2323 
     
    2626          $(OBJ)cmvtstsch.o $(OBJ)cmvtstblack.o $(OBJ)cmvtvarspec.o $(OBJ)cmvdefsurv.o \
    2727          $(OBJ)cmvobserv3d.o $(OBJ)cmvtintfun.o \
    28           $(OBJ)cmvtpoisson.o $(OBJ)cmvconchprof.o $(OBJ)cmvtluc.o
     28          $(OBJ)cmvtpoisson.o $(OBJ)cmvconcherr.o $(OBJ)cmvtluc.o
    2929 
    3030LIBROBJ = \
     
    148148
    149149##############################################################################
    150 cmvconchprof: $(EXE)cmvconchprof
     150cmvconcherr: $(EXE)cmvconcherr
    151151        echo $@ " done"
    152 $(EXE)cmvconchprof: $(OBJ)cmvconchprof.o $(LIB)libcmvsimbao.a
    153         $(CXXLINK) $(CXXREP) -o $@ $(OBJ)cmvconchprof.o $(MYLIB)
    154 $(OBJ)cmvconchprof.o: cmvconchprof.cc
    155         $(CXXCOMPILE) $(CXXREP) -I$(MYEXTINC) -o $@ cmvconchprof.cc
     152$(EXE)cmvconcherr: $(OBJ)cmvconcherr.o $(LIB)libcmvsimbao.a
     153        $(CXXLINK) $(CXXREP) -o $@ $(OBJ)cmvconcherr.o $(MYLIB)
     154$(OBJ)cmvconcherr.o: cmvconcherr.cc
     155        $(CXXCOMPILE) $(CXXREP) -I$(MYEXTINC) -o $@ cmvconcherr.cc
    156156
    157157
  • trunk/Cosmo/SimLSS/arrctcast.h

    r3115 r3141  
    6969TArray<T> ArrCastC2R(TArray< complex<T> > & a) 
    7070{
    71   T x;
     71  T x = 0;
    7272  return ArrayCast(a, x);
    7373}
     
    7878TArray< complex<T> > ArrCastR2C(TArray< T > & a) 
    7979{
    80   complex<T> x;
     80  complex<T> x = 0;
    8181  //  return ArrayCast< TArray< T > , complex<T> > (a, x);
    8282  return ArrayCast(a, x);
     
    8989TArray<T> SDRealPart(TArray< complex<T> > & a) 
    9090{
    91   T x;
     91  T x = 0;
    9292  return ArrayCast(a, x, 0, 2);
    9393}
     
    9898TArray<T> SDImagPart(TArray< complex<T> > & a) 
    9999{
    100   T x;
     100  T x = 0;
    101101  return ArrayCast(a, x, 1, 2);
    102102}
  • trunk/Cosmo/SimLSS/cmvobserv3d.cc

    r3134 r3141  
    1010#include "ntuple.h"
    1111#include "matharr.h"
    12 #include "srandgen.h"
    13 #include "perandom.h"
    14 #include "fabtwriter.h"
    15 
    16 #include "arrctcast.h"
    1712
    1813#include "constcosmo.h"
     
    208203 pkz.SetZ(zref);
    209204 TArray< complex<r_8> > pkgen;
    210  GeneFluct3D fluct3d(pkgen,pkz);
     205 GeneFluct3D fluct3d(pkgen);
    211206 fluct3d.SetNThread(nthread);
    212207 fluct3d.SetSize(nx,ny,nz,dx,dy,dz);
     208 TArray<r_8>& rgen = fluct3d.GetRealArray();
    213209 fluct3d.Print();
     210
     211 double dkmin = fluct3d.GetKincMin();
    214212 double knyqmax = fluct3d.GetKmax();
    215  double dkmin = fluct3d.GetKinc()[0];
     213 long nherr = long(knyqmax/dkmin+0.5);
     214 cout<<"For HistoErr: d="<<dkmin<<" max="<<knyqmax<<" n="<<nherr<<endl;
     215
     216 double dktmin = fluct3d.GetKTincMin();
     217 double ktnyqmax = fluct3d.GetKTmax();
     218 long nherrt = long(ktnyqmax/dktmin+0.5);
     219 double dkzmin = fluct3d.GetKinc()[2];
     220 double kznyqmax = fluct3d.GetKnyq()[2];
     221 long nherrz = long(kznyqmax/dkzmin+0.5);
     222 cout<<"For Histo2DErr: d="<<dktmin<<","<<dkzmin
     223     <<" max="<<ktnyqmax<<","<<kznyqmax<<" n="<<nherrt<<","<<nherrz<<endl;
    216224
    217225 cout<<"\n--- Computing spectra variance up to Kmax at z="<<pkz.GetZ()<<endl;
     
    219227 // sphere: Vs = 4Pi/3 k^3 , cube inscrit (cote k*sqrt(2)): Vc = (k*sqrt(2))^3
    220228 // Vc/Vs = 0.675   ->  keff = kmax * (0.675)^(1/3) = kmax * 0.877
    221  knyqmax *= 0.877;
    222  ldlkint = (log10(knyqmax)-log10(k1int))/npt;
     229 double knyqmax_mod = 0.877*knyqmax;
     230 ldlkint = (log10(knyqmax_mod)-log10(k1int))/npt;
    223231 varpk_int.SetInteg(0.01,ldlkint,-1.,4);
    224  double sr2int_kmax = varpk_int.Variance(R,k1int,knyqmax);
    225  cout<<"varpk_int(<"<<knyqmax<<")="<<sr2int_kmax<<"  ->  sigma="<<sqrt(sr2int_kmax)<<endl;
     232 double sr2int_kmax = varpk_int.Variance(R,k1int,knyqmax_mod);
     233 cout<<"varpk_int(<"<<knyqmax_mod<<")="<<sr2int_kmax<<"  ->  sigma="<<sqrt(sr2int_kmax)<<endl;
    226234
    227235 cout<<"\n--- Computing a realization in Fourier space"<<endl;
    228  if(computefourier0) fluct3d.ComputeFourier0();
    229    else              fluct3d.ComputeFourier();
    230 
    231  cout<<"\n--- Checking realization spectra"<<endl;
    232  long nhprof = long(fluct3d.GetKmax()/dkmin+0.5);
    233  HProf hpkgen(0.,fluct3d.GetKmax(),nhprof);
    234  hpkgen.ReCenterBin();
    235  fluct3d.ComputeSpectrum(hpkgen);
    236  {
    237  tagobs = "hpkgen"; posobs.PutObject(hpkgen,tagobs);
     236 if(computefourier0) fluct3d.ComputeFourier0(pkz);
     237   else              fluct3d.ComputeFourier(pkz);
     238
     239 if(1) {
     240   cout<<"\n--- Checking realization spectra"<<endl;
     241   HistoErr hpkgen(0.,knyqmax,nherr);
     242   hpkgen.ReCenterBin(); hpkgen.Zero();
     243   hpkgen.Show();
     244   fluct3d.ComputeSpectrum(hpkgen);
     245   {
     246   tagobs = "hpkgen"; posobs.PutObject(hpkgen,tagobs);
     247   }
     248 }
     249
     250 if(1) {
     251   cout<<"\n--- Checking realization 2D spectra"<<endl;
     252   Histo2DErr hpkgen2(0.,ktnyqmax,nherrt,0.,kznyqmax,nherrz);
     253   hpkgen2.ReCenterBin(); hpkgen2.Zero();
     254   hpkgen2.Show();
     255   fluct3d.ComputeSpectrum2D(hpkgen2);
     256   {
     257   tagobs = "hpkgen2"; posobs.PutObject(hpkgen2,tagobs);
     258   }
    238259 }
    239260
     
    241262   cout<<"\n--- Computing convolution by pixel shape"<<endl;
    242263   fluct3d.FilterByPixel();
    243 
     264 }
     265
     266 if(1) fluct3d.WriteFits("!cmvobserv3d_k.fits");
     267 if(1) fluct3d.WritePPF("cmvobserv3d_k.ppf",false);
     268
     269 if(1) {
    244270   cout<<"\n--- Checking realization spectra after pixel shape convol."<<endl;
    245    HProf hpkgenf(hpkgen); hpkgenf.Zero();
     271   HistoErr hpkgenf(0.,knyqmax,nherr);
     272   hpkgenf.ReCenterBin(); hpkgenf.Zero();
     273   hpkgenf.Show();
    246274   fluct3d.ComputeSpectrum(hpkgenf);
    247275   {
     
    250278 }
    251279
    252  if(0) {
    253    cout<<"\n--- Writing cmvobserv3dk.ppf"<<endl;
    254    string tag = "cmvobserv3dk.ppf";
    255    POutPersist pos(tag);
    256    tag = "pkgen"; pos.PutObject(pkgen,tag);
     280 if(1) {
     281   cout<<"\n--- Checking realization 2D spectra after pixel shape convol."<<endl;
     282   Histo2DErr hpkgenf2(0.,ktnyqmax,nherrt,0.,kznyqmax,nherrz);
     283   hpkgenf2.ReCenterBin(); hpkgenf2.Zero();
     284   hpkgenf2.Show();
     285   fluct3d.ComputeSpectrum2D(hpkgenf2);
     286   {
     287   tagobs = "hpkgenf2"; posobs.PutObject(hpkgenf2,tagobs);
     288   }
    257289 }
    258290
    259291 cout<<"\n--- Computing a realization in real space"<<endl;
    260292 fluct3d.ComputeReal();
    261  r_8 undouble=0.;
    262  TArray<r_8> rgen = ArrayCast(pkgen,undouble);
    263293 double rmin,rmax; rgen.MinMax(rmin,rmax);
    264294 cout<<"rgen.Min = "<<rmin<<" , Max="<<rmax<<endl;
    265295
    266  cout<<"\n--- Check mean and variance in real space"<<endl;
    267  int_8 nlowone = fluct3d.NumberOfBad(-1.,1e+200);
    268  double rm,rs2; int_8 nm;
    269  nm = fluct3d.MeanSigma2(rm,rs2);
    270  cout<<"rgen:("<<nm<<") Mean = "<<rm<<", Sigma^2 = "
    271      <<rs2<<" -> "<<sqrt(rs2)<<",  n(<-1)="<<nlowone<<endl;
     296 if(1) fluct3d.WriteFits("!cmvobserv3d_r0.fits");
     297 if(1) fluct3d.WritePPF("cmvobserv3d_r0.ppf",true);
     298
     299 int_8 nm;
     300 double rm,rs2;
     301 if(1) {
     302   cout<<"\n--- Check mean and variance in real space"<<endl;
     303   int_8 nlowone = fluct3d.NumberOfBad(-1.,1e+200);
     304   nm = fluct3d.MeanSigma2(rm,rs2);
     305   cout<<"rgen:("<<nm<<") Mean = "<<rm<<", Sigma^2 = "
     306       <<rs2<<" -> "<<sqrt(rs2)<<",  n(<-1)="<<nlowone<<endl;
     307 }
    272308
    273309 if(1) {
     
    331367     <<rs2<<" -> "<<sqrt(rs2)<<endl;
    332368
    333  if(1) {
    334    cout<<"\n---Writing Cube to Fits file"<<endl;
    335    FitsImg3DWriter fwrt("!cmvobserv3dr.fits",FLOAT_IMG,5);
    336    fwrt.WriteKey("ZREF",zref," redshift");
    337    vector<long> n = fluct3d.GetNpix();
    338    fwrt.WriteKey("NX",n[0]," axe transverse 1");
    339    fwrt.WriteKey("NY",n[1]," axe transverse 2");
    340    fwrt.WriteKey("NZ",n[2]," axe longitudinal (redshift)");
    341    vector<r_8> d;
    342    d = fluct3d.GetDinc();
    343    fwrt.WriteKey("DX",d[0]," Mpc");
    344    fwrt.WriteKey("DY",d[1]," Mpc");
    345    fwrt.WriteKey("DZ",d[2]," Mpc");
    346    d = fluct3d.GetKinc();
    347    fwrt.WriteKey("DKX",d[0]," Mpc^-1");
    348    fwrt.WriteKey("DKY",d[1]," Mpc^-1");
    349    fwrt.WriteKey("DKZ",d[2]," Mpc^-1");
    350    fwrt.WriteKey("SNOISE",snoise," Msol");
    351    fwrt.Write(rgen);
    352  }
     369 if(1) fluct3d.WriteFits("!cmvobserv3d_r.fits");
     370 if(1) fluct3d.WritePPF("cmvobserv3d_r.ppf",true);
    353371
    354372 cout<<"\n--- Add noise to HI Flux snoise="<<snoise<<endl;
     
    358376     <<rs2<<" -> "<<sqrt(rs2)<<endl;
    359377
    360  if(0) {
    361    cout<<"\n--- Writing cmvobserv3dr.ppf"<<endl;
    362    string tag = "cmvobserv3dr.ppf";
    363    POutPersist pos(tag);
    364    tag = "rgen"; pos.PutObject(rgen,tag);
    365  }
    366 
    367378 //-----------------------------------------------------------------
    368379 // -- NE PAS FAIRE CA SI ON VEUT CONTINUER LA SIMULATION -> d_rho/rho ecrase
     380 
    369381 if(1) {
    370382   cout<<endl<<"\n--- ReComputing spectrum from real space"<<endl;
    371383   fluct3d.ReComputeFourier();
    372    HProf hpkrec(0.,fluct3d.GetKmax(),nhprof);
     384 }
     385
     386 if(1) {
     387   cout<<endl<<"\n--- Computing final spectrum"<<endl;
     388   HistoErr hpkrec(0.,knyqmax,nherr);
    373389   hpkrec.ReCenterBin();
     390   hpkrec.Show();
    374391   fluct3d.ComputeSpectrum(hpkrec);
    375392   tagobs = "hpkrec"; posobs.PutObject(hpkrec,tagobs);
    376393 }
    377394
     395 if(1) {
     396   cout<<"\n--- Computing final 2D spectrum"<<endl;
     397   Histo2DErr hpkrec2(0.,ktnyqmax,nherrt,0.,kznyqmax,nherrz);
     398   hpkrec2.ReCenterBin(); hpkrec2.Zero();
     399   hpkrec2.Show();
     400   fluct3d.ComputeSpectrum2D(hpkrec2);
     401   {
     402   tagobs = "hpkrec2"; posobs.PutObject(hpkrec2,tagobs);
     403   }
     404 }
     405
    378406 return 0;
    379407}
    380408
    381409/*
    382 openppf cmvobserv3dk.ppf
    383 openppf cmvobserv3dr.ppf
     410######################################################
     411readfits cmvobserv3d_k.fits
     412readfits cmvobserv3d_r0.fits
     413readfits cmvobserv3d_r.fits
     414
     415openppf cmvobserv3d_k.ppf
     416openppf cmvobserv3d_r0.ppf
     417openppf cmvobserv3d_r.ppf
     418
     419# pour le plot 2D d'une slice en Z du 3D: to2d nom_obj3D num_slice
     420defscript to2d
     421 objaoper $1 sliceyz $2
     422 mv sliceyz_${2} ${1}_$2
     423 disp ${1}_$2
     424 echo display slice $2 of $1
     425endscript
     426
     427to2d $cobj 0
     428
     429######################################################
    384430openppf cmvobserv3d.ppf
    385431
    386 objaoper pkgen sliceyz 0
    387 
     432zone
    388433n/plot hpkz.val%x ! ! "nsta connectpoints"
    389434n/plot hpkgen.val%log10(x) x>0 ! "nsta same red connectpoints"
     
    394439n/plot hpkz.val*$k*$k/(2*M_PI*M_PI)%x ! "connectpoints"
    395440
    396 defscript rgensl
    397  objaoper rgen sliceyz $1
    398  disp sliceyz_$1
    399 endscript
    400 
    401 rgensl 0
    402 
     441zone 2 2
     442imag hpkgen2
     443imag hpkgenf2
     444imag hpkrec2
     445
     446zone
    403447disp hmdndm
    404448disp tirhmdndm
  • trunk/Cosmo/SimLSS/genefluct3d.cc

    r3134 r3141  
    1414#include "srandgen.h"
    1515
     16#include "fabtcolread.h"
     17#include "fabtwriter.h"
     18#include "fioarr.h"
     19
     20#include "arrctcast.h"
     21
    1622#include "constcosmo.h"
    1723#include "integfunc.h"
     
    2531
    2632//-------------------------------------------------------
    27 GeneFluct3D::GeneFluct3D(TArray< complex<r_8 > >& T,PkSpectrumZ& pkz)
    28   : T_(T) , pkz_(pkz)
     33GeneFluct3D::GeneFluct3D(TArray< complex<r_8 > >& T)
     34  : T_(T) , array_allocated_(false)
    2935{
    3036 SetNThread();
    31  SetSize(1,-1,1,1.,-1.,1.);
    3237}
    3338
     
    4449void GeneFluct3D::SetSize(long nx,long ny,long nz,double dx,double dy,double dz)
    4550{
    46  if(nx<=0 || dx<=0. ) {
     51  setsize(nx,ny,nz,dx,dy,dz);
     52  setalloc();
     53  setpointers(false);
     54}
     55
     56void GeneFluct3D::setsize(long nx,long ny,long nz,double dx,double dy,double dz)
     57{
     58 if(nx<=0 || dx<=0.) {
    4759   cout<<"GeneFluct3D::SetSize_Error: bad value(s)"<<endl;
    4860   throw ParmError("GeneFluct3D::SetSize_Error: bad value(s)");
    4961 }
    5062
    51  Tcontent_ = 0;
    52 
    53  // Les taille des tableaux
     63 // Les tailles des tableaux
    5464 Nx_ = nx;
    5565 Ny_ = ny;  if(Ny_ <= 0) Ny_ = Nx_;
    5666 Nz_ = nz;  if(Nz_ <= 0) Nz_ = Nx_;
     67 N_.resize(0); N_.push_back(Nx_); N_.push_back(Ny_); N_.push_back(Nz_);
    5768 NRtot_ = Nx_*Ny_*Nz_; // nombre de pixels dans le survey
    5869 NCz_ =  Nz_/2 +1;
    5970 NTz_ = 2*NCz_;
    60  SzK_[2] = Nx_; SzK_[1] = Ny_; SzK_[0] = NCz_; // a l'envers
    6171
    6272 // le pas dans l'espace (Mpc)
     
    6474 Dy_ = dy; if(Dy_ <= 0.) Dy_ = Dx_;
    6575 Dz_ = dz; if(Dz_ <= 0.) Dz_ = Dx_;
     76 D_.resize(0); D_.push_back(Dx_); D_.push_back(Dy_); D_.push_back(Dz_);
    6677 dVol_ = Dx_*Dy_*Dz_;
    6778 Vol_ = (Nx_*Dx_)*(Ny_*Dy_)*(Nz_*Dz_);
     
    7182 Dky_ = 2.*M_PI/(Ny_*Dy_);
    7283 Dkz_ = 2.*M_PI/(Nz_*Dz_);
     84 Dk_.resize(0); Dk_.push_back(Dkx_); Dk_.push_back(Dky_); Dk_.push_back(Dkz_);
    7385 Dk3_ = Dkx_*Dky_*Dkz_;
    7486 
     
    7789 Knyqy_ = M_PI/Dy_;
    7890 Knyqz_ = M_PI/Dz_;
    79 
     91 Knyq_.resize(0); Knyq_.push_back(Knyqx_); Knyq_.push_back(Knyqy_); Knyq_.push_back(Knyqz_);
     92}
     93
     94void GeneFluct3D::setalloc(void)
     95{
     96 // Dimensionnement du tableau complex<r_8>
     97 // ATTENTION: TArray adresse en memoire a l'envers du C
     98 //            Tarray(n1,n2,n3) == Carray[n3][n2][n1]
     99 sa_size_t SzK_[3] = {NCz_,Ny_,Nx_}; // a l'envers
     100 try {
     101   T_.ReSize(3,SzK_);
     102   array_allocated_ = true;
     103 } catch (...) {
     104   cout<<"GeneFluct3D::SetSize_Error: Problem allocating T_"<<endl;
     105 }
     106 T_.SetMemoryMapping(BaseArray::CMemoryMapping);
     107}
     108
     109void GeneFluct3D::setpointers(bool from_real)
     110{
     111 if(from_real) T_ = ArrCastR2C(R_);
     112   else        R_ = ArrCastC2R(T_);
     113 // On remplit les pointeurs
     114 fdata_ = (fftw_complex *) (&T_(0,0,0));
     115 data_ = (double *) (&R_(0,0,0));
     116}
     117
     118void GeneFluct3D::check_array_alloc(void)
     119// Pour tester si le tableau T_ est alloue
     120{
     121 if(array_allocated_) return;
     122 char bla[90];
     123 sprintf(bla,"GeneFluct3D::check_array_alloc_Error: array is not allocated");
     124 cout<<bla<<endl;
     125 throw ParmError(bla);
     126}
     127
     128
     129//-------------------------------------------------------
     130void GeneFluct3D::WriteFits(string cfname,int bitpix)
     131{
     132 cout<<"GeneFluct3D::WriteFits: Writing Cube to "<<cfname<<endl;
     133 try {
     134   FitsImg3DWriter fwrt(cfname.c_str(),bitpix,5);
     135   fwrt.WriteKey("NX",Nx_," axe transverse 1");
     136   fwrt.WriteKey("NY",Ny_," axe transverse 2");
     137   fwrt.WriteKey("NZ",Nz_," axe longitudinal (redshift)");
     138   fwrt.WriteKey("DX",Dx_," Mpc");
     139   fwrt.WriteKey("DY",Dy_," Mpc");
     140   fwrt.WriteKey("DZ",Dz_," Mpc");
     141   fwrt.WriteKey("DKX",Dkx_," Mpc^-1");
     142   fwrt.WriteKey("DKY",Dky_," Mpc^-1");
     143   fwrt.WriteKey("DKZ",Dkz_," Mpc^-1");
     144   fwrt.Write(R_);
     145 } catch (PThrowable & exc) {
     146   cout<<"Exception : "<<(string)typeid(exc).name()
     147       <<" - Msg= "<<exc.Msg()<<endl;
     148   return;
     149 } catch (...) {
     150   cout<<" some other exception was caught !"<<endl;
     151   return;
     152 }
     153}
     154
     155void GeneFluct3D::ReadFits(string cfname)
     156{
     157 cout<<"GeneFluct3D::ReadFits: Reading Cube from "<<cfname<<endl;
     158 try {
     159   FitsImg3DRead fimg(cfname.c_str(),0,5);
     160   fimg.Read(R_);
     161   long nx = fimg.ReadKeyL("NX");
     162   long ny = fimg.ReadKeyL("NY");
     163   long nz = fimg.ReadKeyL("NZ");
     164   double dx = fimg.ReadKey("DX");
     165   double dy = fimg.ReadKey("DY");
     166   double dz = fimg.ReadKey("DZ");
     167   setsize(nx,ny,nz,dx,dy,dz);
     168   setpointers(true);
     169 } catch (PThrowable & exc) {
     170   cout<<"Exception : "<<(string)typeid(exc).name()
     171       <<" - Msg= "<<exc.Msg()<<endl;
     172   return;
     173 } catch (...) {
     174   cout<<" some other exception was caught !"<<endl;
     175   return;
     176 }
     177}
     178
     179void GeneFluct3D::WritePPF(string cfname,bool write_real)
     180// On ecrit soit le TArray<r_8> ou le TArray<complex <r_8> >
     181{
     182 cout<<"GeneFluct3D::WritePPF: Writing Cube (real="<<write_real<<") to "<<cfname<<endl;
     183 try {
     184   R_.Info()["NX"] = (int_8)Nx_;
     185   R_.Info()["NY"] = (int_8)Ny_;
     186   R_.Info()["NZ"] = (int_8)Nz_;
     187   R_.Info()["DX"] = (r_8)Dx_;
     188   R_.Info()["DY"] = (r_8)Dy_;
     189   R_.Info()["DZ"] = (r_8)Dz_;
     190   POutPersist pos(cfname.c_str());
     191   if(write_real) pos << PPFNameTag("rgen")  << R_;
     192     else         pos << PPFNameTag("pkgen") << T_;
     193 } catch (PThrowable & exc) {
     194   cout<<"Exception : "<<(string)typeid(exc).name()
     195       <<" - Msg= "<<exc.Msg()<<endl;
     196   return;
     197 } catch (...) {
     198   cout<<" some other exception was caught !"<<endl;
     199   return;
     200 }
     201}
     202
     203void GeneFluct3D::ReadPPF(string cfname)
     204{
     205 cout<<"GeneFluct3D::ReadPPF: Reading Cube from "<<cfname<<endl;
     206 try {
     207   bool from_real = true;
     208   PInPersist pis(cfname.c_str());
     209   string name_tag_k = "pkgen";
     210   bool found_tag_k = pis.GotoNameTag("pkgen");
     211   if(found_tag_k) {
     212     cout<<"           ...reading spectrun into TArray<complex <r_8> >"<<endl;
     213     pis >> PPFNameTag("pkgen")  >> T_;
     214     from_real = false;
     215   } else {
     216     cout<<"           ...reading space into TArray<r_8>"<<endl;
     217     pis >> PPFNameTag("rgen")  >> R_;
     218   }
     219   int_8 nx = R_.Info()["NX"];
     220   int_8 ny = R_.Info()["NY"];
     221   int_8 nz = R_.Info()["NZ"];
     222   r_8 dx = R_.Info()["DX"];
     223   r_8 dy = R_.Info()["DY"];
     224   r_8 dz = R_.Info()["DZ"];
     225   setsize(nx,ny,nz,dx,dy,dz);
     226   setpointers(from_real);
     227 } catch (PThrowable & exc) {
     228   cout<<"Exception : "<<(string)typeid(exc).name()
     229       <<" - Msg= "<<exc.Msg()<<endl;
     230   return;
     231 } catch (...) {
     232   cout<<" some other exception was caught !"<<endl;
     233   return;
     234 }
    80235}
    81236
     
    83238void GeneFluct3D::Print(void)
    84239{
    85  cout<<"GeneFluct3D(T_typ="<<Tcontent_<<"): z="<<pkz_.GetZ()<<endl;
     240 cout<<"GeneFluct3D(T_alloc="<<array_allocated_<<"):"<<endl;
    86241 cout<<"Space Size : nx="<<Nx_<<" ny="<<Ny_<<" nz="<<Nz_<<" ("<<NTz_<<")  size="
    87242     <<NRtot_<<endl;
     
    98253
    99254//-------------------------------------------------------
    100 void GeneFluct3D::ComputeFourier0(void)
     255void GeneFluct3D::ComputeFourier0(GenericFunc& pk_at_z)
    101256// cf ComputeFourier() mais avec autre methode de realisation du spectre
    102257//    (attention on fait une fft pour realiser le spectre)
     
    104259 int lp=2;
    105260
    106  T_.ReSize(3,SzK_);
    107  T_.SetMemoryMapping(BaseArray::CMemoryMapping);
    108 
    109261 // --- Initialisation de fftw3 (attention data est sur-ecrit a l'init)
    110262 if(lp>1) PrtTim("--- ComputeFourier0: before fftw_plan ---");
    111  fftw_complex *fdata = (fftw_complex *) (&T_(0,0,0));
    112  double *data = (double *) (&T_(0,0,0));
    113263#ifdef FFTW_THREAD
    114264 if(nthread_>0) {
     
    118268 }
    119269#endif
    120  pf_ = fftw_plan_dft_r2c_3d(Nx_,Ny_,Nz_,data,fdata,FFTW_ESTIMATE);
    121  pb_ = fftw_plan_dft_c2r_3d(Nx_,Ny_,Nz_,fdata,data,FFTW_ESTIMATE);
     270 pf_ = fftw_plan_dft_r2c_3d(Nx_,Ny_,Nz_,data_,fdata_,FFTW_ESTIMATE);
     271 pb_ = fftw_plan_dft_c2r_3d(Nx_,Ny_,Nz_,fdata_,data_,FFTW_ESTIMATE);
    122272 if(lp>1) PrtTim("--- ComputeFourier0: after fftw_plan ---");
    123273
     
    127277 double sntot = sqrt((double)NRtot_);
    128278 for(long i=0;i<Nx_;i++) for(long j=0;j<Ny_;j++) for(long l=0;l<Nz_;l++) {
    129    int_8 ip = l+NTz_*(j+Ny_*i);
    130    data[ip] = NorRand()/sntot;
     279   int_8 ip = IndexR(i,j,l);
     280   data_[ip] = NorRand()/sntot;
    131281 }
    132282 if(lp>1) PrtTim("--- ComputeFourier0: after gaussian filling ---");
     
    153303       double k = sqrt(kx+ky+kz);
    154304       // cf normalisation: Peacock, Cosmology, formule 16.38 p504
    155        double pk = pkz_(k)/Vol_;
     305       double pk = pk_at_z(k)/Vol_;
    156306       // ici pas de "/2" a cause de la remarque ci-dessus
    157307       T_(l,j,i) *= sqrt(pk);
     
    165315 if(lp>1) PrtTim("--- ComputeFourier0: after Computing power ---");
    166316
    167  Tcontent_ = 1;
    168 
    169317}
    170318
    171319//-------------------------------------------------------
    172 void GeneFluct3D::ComputeFourier(void)
    173 // Calcule une realisation du spectre "pkz_"
     320void GeneFluct3D::ComputeFourier(GenericFunc& pk_at_z)
     321// Calcule une realisation du spectre "pk_at_z"
    174322// Attention: dans TArray le premier indice varie le + vite
    175323// Explication normalisation: see Coles & Lucchin, Cosmology, p264-265
     
    181329{
    182330 int lp=2;
    183  
    184  // --- Dimensionnement du tableau
    185  // ATTENTION: TArray adresse en memoire a l'envers du C
    186  //            Tarray(n1,n2,n3) == Carray[n3][n2][n1]
    187  T_.ReSize(3,SzK_);
    188  T_.SetMemoryMapping(BaseArray::CMemoryMapping);
    189331
    190332 // --- Initialisation de fftw3 (attention data est sur-ecrit a l'init)
    191333 if(lp>1) PrtTim("--- ComputeFourier: before fftw_plan ---");
    192  fftw_complex *fdata = (fftw_complex *) (&T_(0,0,0));
    193  double *data = (double *) (&T_(0,0,0));
    194334#ifdef FFTW_THREAD
    195335 if(nthread_>0) {
     
    199339 }
    200340#endif
    201  pf_ = fftw_plan_dft_r2c_3d(Nx_,Ny_,Nz_,data,fdata,FFTW_ESTIMATE);
    202  pb_ = fftw_plan_dft_c2r_3d(Nx_,Ny_,Nz_,fdata,data,FFTW_ESTIMATE);
     341 pf_ = fftw_plan_dft_r2c_3d(Nx_,Ny_,Nz_,data_,fdata_,FFTW_ESTIMATE);
     342 pb_ = fftw_plan_dft_c2r_3d(Nx_,Ny_,Nz_,fdata_,data_,FFTW_ESTIMATE);
    203343 //fftw_print_plan(pb_); cout<<endl;
    204344 if(lp>1) PrtTim("--- ComputeFourier: after fftw_plan ---");
     
    222362       double k = sqrt(kx+ky+kz);
    223363       // cf normalisation: Peacock, Cosmology, formule 16.38 p504
    224        double pk = pkz_(k)/Vol_;
     364       double pk = pk_at_z(k)/Vol_;
    225365       // Explication de la division par 2: voir perandom.cc
    226366       // ou egalement Coles & Lucchin, Cosmology formula 13.7.2 p279
     
    238378 if(lp>1) PrtTim("--- ComputeFourier: after before Computing power ---");
    239379
    240  Tcontent_ = 1;
    241 
    242380}
    243381
     
    246384// because we want a realization of a real data in real space
    247385{
    248  fftw_complex *fdata = (fftw_complex *) (&T_(0,0,0));
     386 check_array_alloc();
    249387
    250388 // 1./ Le Continu et Nyquist sont reels
     
    259397       long i=0;
    260398       if(ii==1) {if( Nx_%2!=0) continue; else i = Nx_/2;}
    261        int_8 ip = k+NCz_*(j+Ny_*i);
    262        //cout<<"i="<<i<<" j="<<j<<" k="<<k<<" = ("<<fdata[ip][0]<<","<<fdata[ip][1]<<")"<<endl;
    263        fdata[ip][1] = 0.; fdata[ip][0] *= M_SQRT2;
     399       int_8 ip = IndexC(i,j,k);
     400       //cout<<"i="<<i<<" j="<<j<<" k="<<k<<" = ("<<fdata_[ip][0]<<","<<fdata_[ip][1]<<")"<<endl;
     401       fdata_[ip][1] = 0.; fdata_[ip][0] *= M_SQRT2;
    264402       nreal++;
    265403     }
     
    279417     if(jj==1) {if( Ny_%2!=0) continue; else j = Ny_/2;}
    280418     for(long i=1;i<(Nx_+1)/2;i++) {
    281        int_8 ip = k+NCz_*(j+Ny_*i);
    282        int_8 ip1 = k+NCz_*(j+Ny_*(Nx_-i));
    283        fdata[ip1][0] = fdata[ip][0]; fdata[ip1][1] = -fdata[ip][1];
     419       int_8 ip = IndexC(i,j,k);
     420       int_8 ip1 = IndexC(Nx_-i,j,k);
     421       fdata_[ip1][0] = fdata_[ip][0]; fdata_[ip1][1] = -fdata_[ip][1];
    284422       nconj1++;
    285423     }
     
    289427     if(ii==1) {if( Nx_%2!=0) continue; else i = Nx_/2;}
    290428     for(long j=1;j<(Ny_+1)/2;j++) {
    291        int_8 ip = k+NCz_*(j+Ny_*i);
    292        int_8 ip1 = k+NCz_*((Ny_-j)+Ny_*i);
    293        fdata[ip1][0] = fdata[ip][0]; fdata[ip1][1] = -fdata[ip][1];
     429       int_8 ip = IndexC(i,j,k);
     430       int_8 ip1 = IndexC(i,Ny_-j,k);
     431       fdata_[ip1][0] = fdata_[ip][0]; fdata_[ip1][1] = -fdata_[ip][1];
    294432       nconj1++;
    295433     }
     
    307445     for(long i=1;i<Nx_;i++) {
    308446       if(Nx_%2==0 && i==Nx_/2) continue; // on ne retraite pas nyquist en i
    309        int_8 ip = k+NCz_*(j+Ny_*i);
    310        int_8 ip1 = k+NCz_*((Ny_-j)+Ny_*(Nx_-i));
    311        fdata[ip1][0] = fdata[ip][0]; fdata[ip1][1] = -fdata[ip][1];
     447       int_8 ip = IndexC(i,j,k);
     448       int_8 ip1 = IndexC(Nx_-i,Ny_-j,k);
     449       fdata_[ip1][0] = fdata_[ip][0]; fdata_[ip1][1] = -fdata_[ip][1];
    312450       nconj2++;
    313451     }
     
    324462// Calcul la puissance de la realisation du spectre Pk
    325463{
     464 check_array_alloc();
     465
    326466 double s2 = 0.;
    327467 for(long l=0;l<NCz_;l++)
     
    351491{
    352492 int lp=2;
     493 check_array_alloc();
     494
    353495 if(lp>1) PrtTim("--- FilterByPixel: before ---");
    354496
     
    356498   long ii = (i>Nx_/2) ? Nx_-i : i;
    357499   double kx = ii*Dkx_ *Dx_/2;
    358    double pkx = pixelfilter(kx);
     500   double pk_x = pixelfilter(kx);
    359501   for(long j=0;j<Ny_;j++) {
    360502     long jj = (j>Ny_/2) ? Ny_-j : j;
    361503     double ky = jj*Dky_ *Dy_/2;
    362      double pky =  pixelfilter(ky);
     504     double pk_y =  pixelfilter(ky);
    363505     for(long l=0;l<NCz_;l++) {
    364506       double kz = l*Dkz_ *Dz_/2;
    365        double pkz =  pixelfilter(kz);
    366        T_(l,j,i) *= pkx*pky*pkz;
     507       double pk_z =  pixelfilter(kz);
     508       T_(l,j,i) *= pk_x*pk_y*pk_z;
    367509     }
    368510   }
     
    377519{
    378520 int lp=2;
    379 
    380  if( Tcontent_==0 ) {
    381    cout<<"GeneFluct3D::ComputeReal_Error: empty array"<<endl;
    382    throw ParmError("GeneFluct3D::ComputeReal_Error: empty array");
    383  }
     521 check_array_alloc();
    384522
    385523 // On fait la FFT
     
    387525 fftw_execute(pb_);
    388526 if(lp>1) PrtTim("--- ComputeReal: after fftw backward ---");
    389 
    390  Tcontent_ = 2;
    391527}
    392528
     
    395531{
    396532 int lp=2;
     533 check_array_alloc();
    397534
    398535 // On fait la FFT
     
    405542     for(long l=0;l<NCz_;l++) T_(l,j,i) /= complex<r_8>(v);
    406543
    407  Tcontent_ = 3;
    408544 if(lp>1) PrtTim("--- ComputeReal: after fftw forward ---");
    409545}
    410546
    411547//-------------------------------------------------------------------
    412 int GeneFluct3D::ComputeSpectrum(HProf& hp)
    413 // Compute spectrum from "T" and fill HProf "hp"
     548int GeneFluct3D::ComputeSpectrum(HistoErr& herr)
     549// Compute spectrum from "T" and fill HistoErr "herr"
    414550// T : dans le format standard de GeneFuct3D: T(nz,ny,nx)
    415551// cad T(kz,ky,kx) avec  0<kz<kz_nyq  -ky_nyq<ky<ky_nyq  -kx_nyq<kx<kx_nyq
    416552{
    417 
    418  if(hp.NBins()<0) return -1;
    419  hp.Zero();
    420  hp.SetErrOpt(false);
     553 check_array_alloc();
     554
     555 if(herr.NBins()<0) return -1;
     556 herr.Zero();
    421557
    422558 // Attention a l'ordre
     
    431567       double k = sqrt(kx+ky+kz);
    432568       double pk = MODULE2(T_(l,j,i));
    433        hp.Add(k,pk);
    434      }
    435    }
    436  }
    437  hp.UpdateHisto();
     569       herr.Add(k,pk);
     570     }
     571   }
     572 }
     573 herr.ToCorrel();
    438574
    439575 // renormalize to directly compare to original spectrum
    440576 double norm = Vol_;
    441  hp *= norm;
     577 herr *= norm;
     578
     579 return 0;
     580}
     581
     582int GeneFluct3D::ComputeSpectrum2D(Histo2DErr& herr)
     583{
     584 check_array_alloc();
     585
     586 if(herr.NBinX()<0 || herr.NBinY()<0) return -1;
     587 herr.Zero();
     588
     589 // Attention a l'ordre
     590 for(long i=0;i<Nx_;i++) {
     591   long ii = (i>Nx_/2) ? Nx_-i : i;
     592   double kx = ii*Dkx_;  kx *= kx;
     593   for(long j=0;j<Ny_;j++) {
     594     long jj = (j>Ny_/2) ? Ny_-j : j;
     595     double ky = jj*Dky_;  ky *= ky;
     596     double kt = sqrt(kx+ky);
     597     for(long l=0;l<NCz_;l++) {
     598       double kz = l*Dkz_;
     599       double pk = MODULE2(T_(l,j,i));
     600       herr.Add(kt,kz,pk);
     601     }
     602   }
     603 }
     604 herr.ToCorrel();
     605
     606 // renormalize to directly compare to original spectrum
     607 double norm = Vol_;
     608 herr *= norm;
    442609
    443610 return 0;
     
    449616{
    450617 int lp=2;
     618 check_array_alloc();
     619
    451620 if(lp>1) PrtTim("--- VarianceFrReal: before computation ---");
    452621
    453  double *data = (double *) (&T_(0,0,0));
    454622 long dnx = long(R/Dx_+0.5); if(dnx<=0) dnx = 1;
    455623 long dny = long(R/Dy_+0.5); if(dny<=0) dny = 1;
     
    470638             double z = (ll-l)*Dz_; z *= z;
    471639             if(x+y+z>r2) continue;
    472              int_8 ip = ll+NTz_*(jj+Ny_*ii);
    473              s += 1.+data[ip];
     640             int_8 ip = IndexR(ii,jj,ll);
     641             s += 1.+data_[ip];
    474642             n++;
    475643           }
     
    500668//     ->  vmin and vmax are considered as bad
    501669{
    502  double *data = (double *) (&T_(0,0,0));
     670 check_array_alloc();
    503671
    504672 int_8 nbad = 0;
    505673 for(long i=0;i<Nx_;i++) for(long j=0;j<Ny_;j++) for(long l=0;l<Nz_;l++) {
    506    int_8 ip = l+NTz_*(j+Ny_*i);
    507    double v = data[ip];
     674   int_8 ip = IndexR(i,j,l);
     675   double v = data_[ip];
    508676   if(v<=vmin || v>=vmax) nbad++;
    509677 }
     
    516684//   -> mean and sigma^2 are NOT computed with pixels values vmin and vmax
    517685{
    518  double *data = (double *) (&T_(0,0,0));
     686 check_array_alloc();
    519687
    520688 int_8 n = 0;
     
    522690
    523691 for(long i=0;i<Nx_;i++) for(long j=0;j<Ny_;j++) for(long l=0;l<Nz_;l++) {
    524    int_8 ip = l+NTz_*(j+Ny_*i);
    525    double v = data[ip];
     692   int_8 ip = IndexR(i,j,l);
     693   double v = data_[ip];
    526694   if(v<=vmin || v>=vmax) continue;
    527695   rm += v;
     
    542710//     ->  vmin and vmax are set to val0
    543711{
    544  double *data = (double *) (&T_(0,0,0));
     712 check_array_alloc();
    545713
    546714 int_8 nbad = 0;
    547715 for(long i=0;i<Nx_;i++) for(long j=0;j<Ny_;j++) for(long l=0;l<Nz_;l++) {
    548    int_8 ip = l+NTz_*(j+Ny_*i);
    549    double v = data[ip];
    550    if(v<=vmin || v>=vmax) {data[ip] = val0; nbad++;}
     716   int_8 ip = IndexR(i,j,l);
     717   double v = data_[ip];
     718   if(v<=vmin || v>=vmax) {data_[ip] = val0; nbad++;}
    551719 }
    552720
     
    559727{
    560728 int lp=2;
     729 check_array_alloc();
     730
    561731 if(lp>1) PrtTim("--- TurnFluct2Mass: before computation ---");
    562  double *data = (double *) (&T_(0,0,0));
    563732
    564733 for(long i=0;i<Nx_;i++) for(long j=0;j<Ny_;j++) for(long l=0;l<Nz_;l++) {
    565    int_8 ip = l+NTz_*(j+Ny_*i);
    566    data[ip] += 1.;
    567  }
    568 
    569  Tcontent_ = 4;
     734   int_8 ip = IndexR(i,j,l);
     735   data_[ip] += 1.;
     736 }
     737
    570738 if(lp>1) PrtTim("--- TurnFluct2Mass: after computation ---");
    571739}
     
    576744 int lp=2;
    577745 if(lp>1) PrtTim("--- TurnMass2MeanNumber: before computation ---");
    578 
    579  double *data = (double *) (&T_(0,0,0));
    580746
    581747 double m,s2;
     
    596762 double sum = 0.;
    597763 for(long i=0;i<Nx_;i++) for(long j=0;j<Ny_;j++) for(long l=0;l<Nz_;l++) {
    598    int_8 ip = l+NTz_*(j+Ny_*i);
    599    data[ip] *= dn; // par coherence on multiplie aussi les <=0
    600    if(data[ip]>0.) sum += data[ip];  // mais on ne les compte pas
     764   int_8 ip = IndexR(i,j,l);
     765   data_[ip] *= dn; // par coherence on multiplie aussi les <=0
     766   if(data_[ip]>0.) sum += data_[ip];  // mais on ne les compte pas
    601767 }
    602768 if(lp) cout<<sum<<" galaxies put into survey / "<<n_by_mpc3*Vol_<<endl;
    603769
    604  Tcontent_ = 6;
    605770 if(lp>1) PrtTim("--- TurnMass2MeanNumber: after computation ---");
    606771 return sum;
     
    611776{
    612777 int lp=2;
     778 check_array_alloc();
     779
    613780 if(lp>1) PrtTim("--- ApplyPoisson: before computation ---");
    614 
    615  double *data = (double *) (&T_(0,0,0));
    616781
    617782 double sum = 0.;
    618783 for(long i=0;i<Nx_;i++) for(long j=0;j<Ny_;j++) for(long l=0;l<Nz_;l++) {
    619    int_8 ip = l+NTz_*(j+Ny_*i);
    620    double v = data[ip];
     784   int_8 ip = IndexR(i,j,l);
     785   double v = data_[ip];
    621786   if(v>0.) {
    622787     unsigned long dn = PoissRandLimit(v,10.);
    623      data[ip] = (double)dn;
     788     data_[ip] = (double)dn;
    624789     sum += (double)dn;
    625790   }
    626791 }
    627792 if(lp) cout<<sum<<" galaxies put into survey"<<endl;
    628  Tcontent_ = 8;
    629793
    630794 if(lp>1) PrtTim("--- ApplyPoisson: before computation ---");
     
    641805{
    642806 int lp=2;
     807 check_array_alloc();
     808
    643809 if(lp>1) PrtTim("--- TurnNGal2Mass: before computation ---");
    644 
    645   double *data = (double *) (&T_(0,0,0));
    646810
    647811 double sum = 0.;
    648812 for(long i=0;i<Nx_;i++) for(long j=0;j<Ny_;j++) for(long l=0;l<Nz_;l++) {
    649    int_8 ip = l+NTz_*(j+Ny_*i);
    650    double v = data[ip];
     813   int_8 ip = IndexR(i,j,l);
     814   double v = data_[ip];
    651815   if(v>0.) {
    652816     long ngal = long(v+0.1);
    653      data[ip] = 0.;
     817     data_[ip] = 0.;
    654818     for(long i=0;i<ngal;i++) {
    655819       double m = massdist.RandomInterp();  // massdist.Random();
    656820       if(axeslog) m = pow(10.,m);
    657        data[ip] += m;
    658      }
    659      sum += data[ip];
     821       data_[ip] += m;
     822     }
     823     sum += data_[ip];
    660824   }
    661825 }
    662826 if(lp) cout<<sum<<" MSol HI mass put into survey"<<endl;
    663  Tcontent_ = 10;
    664827
    665828 if(lp>1) PrtTim("--- TurnNGal2Mass: after computation ---");
     
    671834{
    672835 int lp=2;
     836 check_array_alloc();
     837
    673838 if(lp>1) PrtTim("--- AddNoise2Real: before computation ---");
    674839
    675  double *data = (double *) (&T_(0,0,0));
    676 
    677840 for(long i=0;i<Nx_;i++) for(long j=0;j<Ny_;j++) for(long l=0;l<Nz_;l++) {
    678    int_8 ip = l+NTz_*(j+Ny_*i);
    679    data[ip] += snoise*NorRand();
    680  }
    681  Tcontent_ = 12;
     841   int_8 ip = IndexR(i,j,l);
     842   data_[ip] += snoise*NorRand();
     843 }
    682844
    683845 if(lp>1) PrtTim("--- AddNoise2Real: after computation ---");
  • trunk/Cosmo/SimLSS/genefluct3d.h

    r3134 r3141  
    55#include "genericfunc.h"
    66#include "tarray.h"
    7 #include "hisprof.h"
     7#include "histerr.h"
     8#include "hist2err.h"
    89#include "perandom.h"
     10
     11#include "FFTW/fftw3.h"
     12#include "FitsIO/fitsio.h"
    913
    1014#include <vector>
     
    1216#include "pkspectrum.h"
    1317
    14 #include "FFTW/fftw3.h"
    1518
    1619namespace SOPHYA {
     
    1922class GeneFluct3D {
    2023public:
    21   GeneFluct3D(TArray< complex<r_8 > >& T,PkSpectrumZ& pkz);
     24  GeneFluct3D(TArray< complex<r_8 > >& T);
    2225  virtual ~GeneFluct3D(void);
    2326
     
    2528  void SetSize(long nx,long ny,long nz,double dx,double dy,double dz);  // Mpc
    2629
    27   inline void SetZ(double z) {pkz_.SetZ(z);}
    28   double GetZ(void) {return pkz_.GetZ();}
     30  TArray< complex<r_8> >& GetComplexArray(void) {return T_;}
     31  fftw_complex* GetComplexPointer(void) {return fdata_;}
     32  TArray<r_8>& GetRealArray(void) {return R_;}
     33  r_8* GetRealPointer(void) {return data_;}
     34
     35  // Pour adressage data_[ip]
     36  inline int_8 IndexR(long i,long j,long k) {return (int_8)(k+NTz_*(j+Ny_*i));}
     37  // Pour adressage fdata_[ip][0-1]
     38  inline int_8 IndexC(long i,long j,long k) {return (int_8)(k+NCz_*(j+Ny_*i));}
     39  // - On peut aussi adresser:
     40  // TArray< complex<r_8> >& pk = gf3d.GetComplexArray(); pk(i,j,k) = ...;
     41  // TArray<r_8>& rgen = gf3d.GetRealArray(); rgen(i,j,k) = ...;
     42
     43  vector<long> GetNpix(void) {return N_;}
     44  int_8 NPix(void) {return NRtot_;}
     45
     46  vector<r_8> GetDinc(void) {return D_;}
     47  double GetDVol(void) {return dVol_;}
    2948  double GetVol(void) {return Vol_;}
    30   double GetDVol(void) {return dVol_;}
    31   int_8 NPix(void) {return NRtot_;}
     49
     50  vector<r_8> GetKinc(void) {return Dk_;}
     51  vector<r_8> GetKnyq(void) {return Knyq_;}
    3252  double GetKmax(void) {return sqrt(Knyqx_*Knyqx_+Knyqy_*Knyqy_+Knyqz_*Knyqz_);}
    33   vector<r_8> GetKinc(void)
    34     {vector<r_8> dk; dk.push_back(Dkx_); dk.push_back(Dky_); dk.push_back(Dkz_); return dk;}
    35   vector<r_8> GetKnyq(void)
    36     {vector<r_8> kn; kn.push_back(Knyqx_); kn.push_back(Knyqy_); kn.push_back(Knyqz_); return kn;}
    37   vector<r_8> GetDinc(void)
    38     {vector<r_8> d; d.push_back(Dx_); d.push_back(Dy_); d.push_back(Dz_); return d;}
    39   vector<long> GetNpix(void)
    40     {vector<long> d; d.push_back(Nx_); d.push_back(Ny_); d.push_back(Nz_); return d;}
     53  double GetKTmax(void) {return sqrt(Knyqx_*Knyqx_+Knyqy_*Knyqy_);}
     54  double GetKincMin(void)
     55    {vector<r_8>::const_iterator it = min_element(Dk_.begin(), Dk_.end()); return *it;}
     56  double GetKTincMin(void) {return min(Dk_[0],Dk_[1]);}
    4157
    42   void ComputeFourier0(void);
    43   void ComputeFourier(void);
     58  void ComputeFourier0(GenericFunc& pk_at_z);
     59  void ComputeFourier(GenericFunc& pk_at_z);
    4460  void FilterByPixel(void);
    45   int  ComputeSpectrum(HProf& hp);
     61
    4662  void ComputeReal(void);
     63
    4764  void ReComputeFourier(void);
     65
     66  int  ComputeSpectrum(HistoErr& herr);
     67  int  ComputeSpectrum2D(Histo2DErr& herr);
    4868
    4969  int_8 VarianceFrReal(double R,double& var);
     
    5979  void AddNoise2Real(double snoise);
    6080
     81  void WriteFits(string cfname,int bitpix=FLOAT_IMG);
     82  void ReadFits(string cfname);
     83
     84  void WritePPF(string cfname,bool write_real=true);
     85  void ReadPPF(string cfname);
     86
    6187  void Print(void);
    6288
    6389protected:
     90  void setsize(long nx,long ny,long nz,double dx,double dy,double dz);
     91  void setalloc(void);
     92  void setpointers(bool from_real);
    6493  long manage_coefficients(void);
    6594  double compute_power_carte(void);
     95  void check_array_alloc(void);
    6696  inline double pixelfilter(double x)
    6797    {return (x<0.025) ? 1.-x*x/6.*(1.-x*x/20.): sin(x)/x;}
    6898
    6999
    70   long Nx_,Ny_,Nz_;
    71   sa_size_t SzK_[3];
     100  long Nx_,Ny_,Nz_;  vector<long> N_;
    72101  long NCz_,NTz_;
    73102  int_8 NRtot_;
    74   double Dx_,Dy_,Dz_;
     103
     104  double Dx_,Dy_,Dz_;  vector<double> D_;
     105
     106  double Dkx_,Dky_,Dkz_;  vector<double> Dk_;
     107  double Knyqx_,Knyqy_,Knyqz_;  vector<double> Knyq_;
     108  double Dk3_;
    75109  double dVol_, Vol_;
    76   double Dkx_,Dky_,Dkz_;
    77   double Knyqx_,Knyqy_,Knyqz_;
    78   double Dk3_;
    79110
    80111  fftw_plan pf_,pb_;
    81112  unsigned short nthread_;
    82113
    83   //   = 0 : T_ vide
    84   //   = 1 : T_ contient une realisation du spectre (espace fourier)
    85   //   = 2 : T_ contient une realisation dans l'espace reel
    86   //   = 3 : T_ contient la TF d'une realisation dans l'espace reel (d_rho/rho)
    87   //   = 4 : T_ contient (1 + d_rho/rho)
    88   //   = ... etc ...
    89   unsigned short Tcontent_;
     114  bool array_allocated_;  // true if array has been allocated
    90115
    91   TArray< complex<r_8 > >& T_;
    92   PkSpectrumZ& pkz_;
     116  TArray< complex<r_8> >& T_;
     117  fftw_complex *fdata_;
     118  TArray<r_8> R_;
     119  double *data_;
    93120};
    94121
  • trunk/Cosmo/SimLSS/genericfunc.h

    r3115 r3141  
    33
    44#include "pexceptions.h"
     5#include <vector>
    56
    67namespace SOPHYA {
     
    3233  }
    3334
     35  virtual double operator()(vector<double>& x) {
     36    cout<<"GenericFunc::operator(vector<double>&) not implemented"<<endl;
     37    throw NotAvailableOperation("GenericFunc::operator(vector<double>&) not implemented");
     38  }
     39
    3440};
    3541
Note: See TracChangeset for help on using the changeset viewer.