Changeset 3155 in Sophya for trunk/Cosmo/SimLSS/genefluct3d.cc


Ignore:
Timestamp:
Jan 19, 2007, 6:18:38 PM (19 years ago)
Author:
cmv
Message:

PrtTim deplaces de genefluct3d.cc -> cmvobserv3d.cc cmv 19/01/2007

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Cosmo/SimLSS/genefluct3d.cc

    r3154 r3155  
    88#include <unistd.h>
    99
    10 #include "timing.h"
    1110#include "tarray.h"
    1211#include "pexceptions.h"
     
    7473void GeneFluct3D::setsize(long nx,long ny,long nz,double dx,double dy,double dz)
    7574{
     75 if(lp_>1) cout<<"--- GeneFluct3D::setsize: N="<<nx<<","<<ny<<","<<nz
     76                <<" D="<<dx<<","<<dy<<","<<dz<<endl;
    7677 if(nx<=0 || dx<=0.) {
    77    cout<<"GeneFluct3D::SetSize_Error: bad value(s)"<<endl;
    78    throw ParmError("GeneFluct3D::SetSize_Error: bad value(s)");
     78   cout<<"GeneFluct3D::setsize_Error: bad value(s)"<<endl;
     79   throw ParmError("GeneFluct3D::setsize_Error: bad value(s)");
    7980 }
    8081
     
    112113void GeneFluct3D::setalloc(void)
    113114{
     115 if(lp_>1) cout<<"--- GeneFluct3D::setalloc ---"<<endl;
    114116 // Dimensionnement du tableau complex<r_8>
    115117 // ATTENTION: TArray adresse en memoire a l'envers du C
     
    120122   array_allocated_ = true;
    121123 } catch (...) {
    122    cout<<"GeneFluct3D::SetSize_Error: Problem allocating T_"<<endl;
     124   cout<<"GeneFluct3D::setalloc_Error: Problem allocating T_"<<endl;
    123125 }
    124126 T_.SetMemoryMapping(BaseArray::CMemoryMapping);
     
    127129void GeneFluct3D::setpointers(bool from_real)
    128130{
     131 if(lp_>1) cout<<"--- GeneFluct3D::setpointers ---"<<endl;
    129132 if(from_real) T_ = ArrCastR2C(R_);
    130133   else        R_ = ArrCastC2R(T_);
     
    147150{
    148151 // --- Initialisation de fftw3 (attention data est sur-ecrit a l'init)
    149  if(lp_>1) PrtTim("--- GeneFluct3D::init_fftw: before fftw_plan ---");
     152 if(lp_>1) cout<<"--- GeneFluct3D::init_fftw ---"<<endl;
    150153#ifdef FFTW_THREAD
    151154 if(nthread_>0) {
    152    cout<<"Computing with "<<nthread_<<" threads"<<endl;
     155   cout<<"...Computing with "<<nthread_<<" threads"<<endl;
    153156   fftw_init_threads();
    154157   fftw_plan_with_nthreads(nthread_);
    155158 }
    156159#endif
     160 if(lp_>1) cout<<"...forward plan"<<endl;
    157161 pf_ = fftw_plan_dft_r2c_3d(Nx_,Ny_,Nz_,data_,fdata_,FFTW_ESTIMATE);
     162 if(lp_>1) cout<<"...backward plan"<<endl;
    158163 pb_ = fftw_plan_dft_c2r_3d(Nx_,Ny_,Nz_,fdata_,data_,FFTW_ESTIMATE);
    159  if(lp_>1) PrtTim("--- GeneFluct3D::init_fftw: after fftw_plan ---");
    160164}
    161165
     
    164168void GeneFluct3D::WriteFits(string cfname,int bitpix)
    165169{
    166  cout<<"GeneFluct3D::WriteFits: Writing Cube to "<<cfname<<endl;
     170 cout<<"--- GeneFluct3D::WriteFits: Writing Cube to "<<cfname<<endl;
    167171 try {
    168172   FitsImg3DWriter fwrt(cfname.c_str(),bitpix,5);
     
    191195void GeneFluct3D::ReadFits(string cfname)
    192196{
    193  cout<<"GeneFluct3D::ReadFits: Reading Cube from "<<cfname<<endl;
     197 cout<<"--- GeneFluct3D::ReadFits: Reading Cube from "<<cfname<<endl;
    194198 try {
    195199   FitsImg3DRead fimg(cfname.c_str(),0,5);
     
    220224// On ecrit soit le TArray<r_8> ou le TArray<complex <r_8> >
    221225{
    222  cout<<"GeneFluct3D::WritePPF: Writing Cube (real="<<write_real<<") to "<<cfname<<endl;
     226 cout<<"--- GeneFluct3D::WritePPF: Writing Cube (real="<<write_real<<") to "<<cfname<<endl;
    223227 try {
    224228   R_.Info()["NX"] = (int_8)Nx_;
     
    245249void GeneFluct3D::ReadPPF(string cfname)
    246250{
    247  cout<<"GeneFluct3D::ReadPPF: Reading Cube from "<<cfname<<endl;
     251 cout<<"--- GeneFluct3D::ReadPPF: Reading Cube from "<<cfname<<endl;
    248252 try {
    249253   bool from_real = true;
     
    306310
    307311 // --- realisation d'un tableau de tirage gaussiens
    308  if(lp_>1) PrtTim("--- ComputeFourier0: before gaussian filling ---");
     312 if(lp_>0) cout<<"--- ComputeFourier0: before gaussian filling ---"<<endl;
    309313 // On tient compte du pb de normalisation de FFTW3
    310314 double sntot = sqrt((double)NRtot_);
     
    313317   data_[ip] = NorRand()/sntot;
    314318 }
    315  if(lp_>1) PrtTim("--- ComputeFourier0: after gaussian filling ---");
    316319
    317320 // --- realisation d'un tableau de tirage gaussiens
    318  if(lp_>1) PrtTim("--- ComputeFourier0: before fft real ---");
     321 if(lp_>0) cout<<"...before fft real ---"<<endl;
    319322 fftw_execute(pf_);
    320  if(lp_>1) PrtTim("--- ComputeFourier0: after fft real ---");
    321323
    322324 // --- On remplit avec une realisation
    323  if(lp_>1) PrtTim("--- ComputeFourier0: before Fourier realization filling ---");
     325 if(lp_>0) cout<<"...before Fourier realization filling ---"<<endl;
    324326 T_(0,0,0) = complex<r_8>(0.);  // on coupe le continue et on l'initialise
    325327 long lmod = Nx_/10; if(lmod<1) lmod=1;
     
    327329   long ii = (i>Nx_/2) ? Nx_-i : i;
    328330   double kx = ii*Dkx_;  kx *= kx;
    329    if(lp_>1 && i%lmod==0) cout<<"i="<<i<<" ii="<<ii<<endl;
     331   if(lp_>0 && i%lmod==0) cout<<"i="<<i<<" ii="<<ii<<endl;
    330332   for(long j=0;j<Ny_;j++) {
    331333     long jj = (j>Ny_/2) ? Ny_-j : j;
     
    342344   }
    343345 }
    344  if(lp_>1) PrtTim("--- ComputeFourier0: after Fourier realization filling ---");
    345 
     346
     347 if(lp_>0) cout<<"...computing power"<<endl;
    346348 double p = compute_power_carte();
    347  cout<<"Puissance dans la realisation: "<<p<<endl;
    348  if(lp_>1) PrtTim("--- ComputeFourier0: after Computing power ---");
     349 if(lp_>0) cout<<"Puissance dans la realisation: "<<p<<endl;
    349350
    350351}
     
    365366
    366367 // --- On remplit avec une realisation
    367  if(lp_>1) PrtTim("--- ComputeFourier: before Fourier realization filling ---");
     368 if(lp_>0) cout<<"--- ComputeFourier ---"<<endl;
    368369 long lmod = Nx_/10; if(lmod<1) lmod=1;
    369370 for(long i=0;i<Nx_;i++) {
    370371   long ii = (i>Nx_/2) ? Nx_-i : i;
    371372   double kx = ii*Dkx_;  kx *= kx;
    372    if(lp_>1 && i%lmod==0) cout<<"i="<<i<<" ii="<<ii<<endl;
     373   if(lp_>0 && i%lmod==0) cout<<"i="<<i<<" ii="<<ii<<endl;
    373374   for(long j=0;j<Ny_;j++) {
    374375     long jj = (j>Ny_/2) ? Ny_-j : j;
     
    386387   }
    387388 }
    388  if(lp_>1) PrtTim("--- ComputeFourier: after Fourier realization filling ---");
    389389
    390390 manage_coefficients();   // gros effet pour les spectres que l'on utilise !
    391  if(lp_>1) PrtTim("--- ComputeFourier: after managing coefficients ---");
    392 
     391
     392 if(lp_>0) cout<<"...computing power"<<endl;
    393393 double p = compute_power_carte();
    394  cout<<"Puissance dans la realisation: "<<p<<endl;
    395  if(lp_>1) PrtTim("--- ComputeFourier: after before Computing power ---");
     394 if(lp_>0) cout<<"Puissance dans la realisation: "<<p<<endl;
    396395
    397396}
     
    401400// because we want a realization of a real data in real space
    402401{
     402 if(lp_>1) cout<<"...managing coefficients"<<endl;
    403403 check_array_alloc();
    404404
     
    421421   }
    422422 }
    423  cout<<"Number of forced real number ="<<nreal<<endl;
     423 if(lp_>1) cout<<"Number of forced real number ="<<nreal<<endl;
    424424
    425425 // 2./ Les elements complexe conjugues (tous dans le plan k=0,Nyquist)
     
    451451   }
    452452 }
    453  cout<<"Number of forced conjugate on cont+nyq ="<<nconj1<<endl;
     453 if(lp_>1) cout<<"Number of forced conjugate on cont+nyq ="<<nconj1<<endl;
    454454
    455455 // b./ les lignes et colonnes hors continu et de nyquist
     
    469469   }
    470470 }
    471  cout<<"Number of forced conjugate hors cont+nyq ="<<nconj2<<endl;
    472 
    473  cout<<"Check: ddl= "<<NRtot_<<" =?= "<<2*(Nx_*Ny_*NCz_-nconj1-nconj2)-8<<endl;
     471 if(lp_>1) cout<<"Number of forced conjugate hors cont+nyq ="<<nconj2<<endl;
     472
     473 if(lp_>1) cout<<"Check: ddl= "<<NRtot_<<" =?= "<<2*(Nx_*Ny_*NCz_-nconj1-nconj2)-8<<endl;
    474474
    475475 return nreal+nconj1+nconj2;
     
    507507//                          avec y = k_x*dx/2
    508508{
    509  check_array_alloc();
    510 
    511  if(lp_>1) PrtTim("--- FilterByPixel: before ---");
     509 if(lp_>0) cout<<"--- FilterByPixel ---"<<endl;
     510 check_array_alloc();
    512511
    513512 for(long i=0;i<Nx_;i++) {
     
    527526 }
    528527
    529  if(lp_>1) PrtTim("--- FilterByPixel: after ---");
    530528}
    531529
     
    534532// Calcule une realisation dans l'espace reel
    535533{
     534 if(lp_>0) cout<<"--- ComputeReal ---"<<endl;
    536535 check_array_alloc();
    537536
    538537 // On fait la FFT
    539  if(lp_>1) PrtTim("--- ComputeReal: before fftw backward ---");
    540538 fftw_execute(pb_);
    541  if(lp_>1) PrtTim("--- ComputeReal: after fftw backward ---");
    542539}
    543540
     
    545542void GeneFluct3D::ReComputeFourier(void)
    546543{
     544 if(lp_>0) cout<<"--- ReComputeFourier ---"<<endl;
    547545 check_array_alloc();
    548546
    549547 // On fait la FFT
    550  if(lp_>1) PrtTim("--- ComputeReal: before fftw forward ---");
    551548 fftw_execute(pf_);
    552549 // On corrige du pb de la normalisation de FFTW3
     
    556553     for(long l=0;l<NCz_;l++) T_(l,j,i) /= complex<r_8>(v);
    557554
    558  if(lp_>1) PrtTim("--- ComputeReal: after fftw forward ---");
    559555}
    560556
     
    565561// cad T(kz,ky,kx) avec  0<kz<kz_nyq  -ky_nyq<ky<ky_nyq  -kx_nyq<kx<kx_nyq
    566562{
    567  check_array_alloc();
    568  if(lp_>1) PrtTim("--- ComputeSpectrum: before ---");
     563 if(lp_>0) cout<<"--- ComputeSpectrum ---"<<endl;
     564 check_array_alloc();
    569565
    570566 if(herr.NBins()<0) return -1;
     
    592588 herr *= norm;
    593589
    594  if(lp_>1) PrtTim("--- ComputeSpectrum: after ---");
    595 
    596590 return 0;
    597591}
     
    599593int GeneFluct3D::ComputeSpectrum2D(Histo2DErr& herr)
    600594{
    601  check_array_alloc();
    602  if(lp_>1) PrtTim("--- ComputeSpectrum2D: before ---");
     595 if(lp_>0) cout<<"--- ComputeSpectrum2D ---"<<endl;
     596 check_array_alloc();
    603597
    604598 if(herr.NBinX()<0 || herr.NBinY()<0) return -1;
     
    626620 herr *= norm;
    627621
    628  if(lp_>1) PrtTim("--- ComputeSpectrum2D: after ---");
    629 
    630622 return 0;
    631623}
     
    635627// Recompute MASS variance in spherical top-hat (rayon=R)
    636628{
    637  check_array_alloc();
    638 
    639  if(lp_>1) PrtTim("--- VarianceFrReal: before computation ---");
     629 if(lp_>0) cout<<"--- VarianceFrReal ---"<<endl;
     630 check_array_alloc();
    640631
    641632 long dnx = long(R/Dx_+0.5); if(dnx<=0) dnx = 1;
    642633 long dny = long(R/Dy_+0.5); if(dny<=0) dny = 1;
    643634 long dnz = long(R/Dz_+0.5); if(dnz<=0) dnz = 1;
    644  cout<<"dnx="<<dnx<<" dny="<<dny<<" dnz="<<dnz<<endl;
     635 if(lp_>0) cout<<"dnx="<<dnx<<" dny="<<dny<<" dnz="<<dnz<<endl;
    645636
    646637 double sum=0., sum2=0., r2 = R*R; int_8 nsum=0;
     
    673664 sum /= nsum;
    674665 sum2 = sum2/nsum - sum*sum;
    675  if(lp_) cout<<"VarianceFrReal: nsum="<<nsum<<" <M>="<<sum<<" <(M-<M>)^2>="<<sum2<<endl;
     666 if(lp_>0) cout<<"VarianceFrReal: nsum="<<nsum<<" <M>="<<sum<<" <(M-<M>)^2>="<<sum2<<endl;
    676667
    677668 var = sum2/(sum*sum);  // <dM>^2/<M>^2
    678  if(lp_) cout<<"sigmaR^2="<<var<<" -> "<<sqrt(var)<<endl;
    679 
    680  if(lp_>1) PrtTim("--- VarianceFrReal: after computation ---");
     669 if(lp_>0) cout<<"sigmaR^2="<<var<<" -> "<<sqrt(var)<<endl;
     670
    681671 return nsum;
    682672}
     
    745735// d_rho/rho -> Mass  (add one!)
    746736{
    747  check_array_alloc();
    748 
    749  if(lp_>1) PrtTim("--- TurnFluct2Mass: before computation ---");
     737 if(lp_>0) cout<<"--- TurnFluct2Mass ---"<<endl;
     738 check_array_alloc();
     739
    750740
    751741 for(long i=0;i<Nx_;i++) for(long j=0;j<Ny_;j++) for(long l=0;l<Nz_;l++) {
     
    753743   data_[ip] += 1.;
    754744 }
    755 
    756  if(lp_>1) PrtTim("--- TurnFluct2Mass: after computation ---");
    757745}
    758746
     
    760748// do NOT treate negative or nul values
    761749{
    762  if(lp_>1) PrtTim("--- TurnMass2MeanNumber: before computation ---");
     750 if(lp_>0) cout<<"--- TurnMass2MeanNumber ---"<<endl;
    763751
    764752 double m,s2;
    765753 int_8 ngood = MeanSigma2(m,s2,0.,1e+200);
    766  if(lp_) cout<<"TurnMass2MeanNumber: ngood="<<ngood
    767             <<" m="<<m<<" s2="<<s2<<" -> "<<sqrt(s2)<<endl;
     754 if(lp_>0) cout<<"...ngood="<<ngood
     755               <<" m="<<m<<" s2="<<s2<<" -> "<<sqrt(s2)<<endl;
    768756
    769757 // On doit mettre n*Vol galaxies dans notre survey
     
    775763 //   (rappel sur tout les pixels <1+d_rho/rho>=1)
    776764 double dn = n_by_mpc3*Vol_/m /(double)ngood;  // nb de gal a mettre ds 1 px
    777  if(lp_) cout<<"galaxy density move from "
    778             <<n_by_mpc3*Vol_/double(NRtot_)<<" to "<<dn<<" / pixel"<<endl;
     765 if(lp_>0) cout<<"...galaxy density move from "
     766               <<n_by_mpc3*Vol_/double(NRtot_)<<" to "<<dn<<" / pixel"<<endl;
    779767 double sum = 0.;
    780768 for(long i=0;i<Nx_;i++) for(long j=0;j<Ny_;j++) for(long l=0;l<Nz_;l++) {
     
    783771   if(data_[ip]>0.) sum += data_[ip];  // mais on ne les compte pas
    784772 }
    785  if(lp_) cout<<sum<<" galaxies put into survey / "<<n_by_mpc3*Vol_<<endl;
    786 
    787  if(lp_>1) PrtTim("--- TurnMass2MeanNumber: after computation ---");
     773 if(lp_>0) cout<<sum<<"...galaxies put into survey / "<<n_by_mpc3*Vol_<<endl;
     774
    788775 return sum;
    789776}
     
    792779// do NOT treate negative or nul mass  -> let it as it is
    793780{
    794  check_array_alloc();
    795 
    796  if(lp_>1) PrtTim("--- ApplyPoisson: before computation ---");
     781 if(lp_>0) cout<<"--- ApplyPoisson ---"<<endl;
     782 check_array_alloc();
    797783
    798784 double sum = 0.;
     
    806792   }
    807793 }
    808  if(lp_) cout<<sum<<" galaxies put into survey"<<endl;
    809 
    810  if(lp_>1) PrtTim("--- ApplyPoisson: before computation ---");
     794 if(lp_>0) cout<<sum<<" galaxies put into survey"<<endl;
     795
    811796 return sum;
    812797}
     
    820805// RETURN la masse totale
    821806{
    822  check_array_alloc();
    823 
    824  if(lp_>1) PrtTim("--- TurnNGal2Mass: before computation ---");
     807 if(lp_>0) cout<<"--- TurnNGal2Mass ---"<<endl;
     808 check_array_alloc();
    825809
    826810 double sum = 0.;
     
    839823   }
    840824 }
    841  if(lp_) cout<<sum<<" MSol HI mass put into survey"<<endl;
    842 
    843  if(lp_>1) PrtTim("--- TurnNGal2Mass: after computation ---");
     825 if(lp_>0) cout<<sum<<" MSol HI mass put into survey"<<endl;
     826
    844827 return sum;
    845828}
     
    848831// add noise to every pixels (meme les <=0 !)
    849832{
    850  check_array_alloc();
    851 
    852  if(lp_>1) PrtTim("--- AddNoise2Real: before computation ---");
     833 if(lp_>0) cout<<"--- AddNoise2Real: snoise = "<<snoise<<endl;
     834 check_array_alloc();
    853835
    854836 for(long i=0;i<Nx_;i++) for(long j=0;j<Ny_;j++) for(long l=0;l<Nz_;l++) {
     
    856838   data_[ip] += snoise*NorRand();
    857839 }
    858 
    859  if(lp_>1) PrtTim("--- AddNoise2Real: after computation ---");
    860 }
     840}
Note: See TracChangeset for help on using the changeset viewer.