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


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

intro du facteur de croissance dans la simul cmv 25/01/2007

File:
1 edited

Legend:

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

    r3155 r3157  
    3232GeneFluct3D::GeneFluct3D(TArray< complex<r_8 > >& T)
    3333  : T_(T) , Nx_(0) , Ny_(0) , Nz_(0) , array_allocated_(false) , lp_(0)
    34   , redshref_(-999.) , kredshref_(-999.)
    35 {
     34  , redshref_(-999.) , kredshref_(0.) , cosmo_(NULL) , growth_(NULL)
     35  , loscom_ref_(-999.), loscom_min_(-999.), loscom_max_(-999.)
     36
     37
     38{
     39 xobs_[0] = xobs_[1] = xobs_[2] = 0.;
     40 zred_.resize(0);
     41 loscom_.resize(0);
    3642 SetNThread();
    3743}
     
    6470//     kredshref = indice (en double) correspondant a ce redshift
    6571//                 Si kredshref<0 alors kredshref=0
     72// Exemple: redshref=1.5 kredshref=250.75
     73//    -> Le pixel i=nx/2 j=ny/2 k=250.75 est au redshift 1.5
    6674{
    6775 if(redshref<0.) redshref = 0.;
    6876 if(kredshref<0.) kredshref = 0.;
    69  redshref_ = redshref;
     77 redshref_  = redshref;
    7078 kredshref_ = kredshref;
     79}
     80
     81void GeneFluct3D::SetCosmology(CosmoCalc& cosmo)
     82{
     83 cosmo_ = &cosmo;
     84 if(lp_>1) cosmo_->Print();
     85}
     86
     87void GeneFluct3D::SetGrowthFactor(GrowthFactor& growth)
     88{
     89 growth_ = &growth;
    7190}
    7291
     
    164183}
    165184
     185//-------------------------------------------------------
     186long GeneFluct3D::LosComRedshift(double zinc)
     187// Given a position of the cube relative to the observer
     188// and a cosmology
     189// (SetObservator() and SetCosmology() should have been called !)
     190// This routine filled:
     191//   the vector "zred_" of scanned redshift (by zinc increments)
     192//   the vector "loscom_" of corresponding los comoving distance
     193//
     194{
     195 if(zinc<=0.) zinc = 0.01;
     196 if(lp_>0) cout<<"--- LosComRedshift: zinc="<<zinc<<endl;
     197
     198 if(cosmo_ == NULL || redshref_<0.) {
     199   cout<<"GeneFluct3D::LosComRedshift_Error: set Observator and Cosmology first"<<endl;
     200   throw ParmError("");
     201 }
     202
     203 // On calcule les coordonnees de l'observateur
     204 // Il est sur un axe centre sur le milieu de la face Oxy
     205 double loscom_ref_ = cosmo_->Dloscom(redshref_);
     206 xobs_[0] = Nx_/2.*Dx_;
     207 xobs_[1] = Ny_/2.*Dy_;
     208 xobs_[2] = kredshref_*Dz_ - loscom_ref_;
     209
     210 // L'observateur est-il dans le cube?
     211 bool obs_in_cube = false;
     212 if(xobs_[2]>=0. && xobs_[2]<=Nz_*Dz_) obs_in_cube = true;
     213
     214 // Find MINIMUM los com distance to the observer:
     215 // c'est le centre de la face a k=0
     216 // (ou zero si l'observateur est dans le cube)
     217 loscom_min_ = 0.;
     218 if(!obs_in_cube) loscom_min_ = -xobs_[2];
     219
     220 // Find MAXIMUM los com distance to the observer:
     221 // ou que soit positionne l'observateur, la distance
     222 // maximal est sur un des coins du cube
     223 loscom_max_ = 0.;
     224 for(long i=0;i<=1;i++) {
     225   double dx2 = xobs_[0] - i*Nx_*Dx_; dx2 *= dx2;
     226   for(long j=0;j<=1;j++) {
     227     double dy2 = xobs_[1] - j*Ny_*Dy_; dy2 *= dy2;
     228     for(long k=0;k<=1;k++) {
     229       double dz2 = xobs_[2] - k*Nz_*Dz_; dz2 *= dz2;
     230       dz2 = sqrt(dx2+dy2+dz2);
     231       if(dz2>loscom_max_) loscom_max_ = dz2;
     232     }
     233   }
     234 }
     235 if(lp_>0) {
     236   cout<<"...zref="<<redshref_<<" kzref="<<kredshref_<<" losref="<<loscom_ref_<<" Mpc\n"
     237       <<"   xobs="<<xobs_[0]<<" , "<<xobs_[1]<<" , "<<xobs_[2]<<" Mpc "
     238       <<" in_cube="<<obs_in_cube
     239       <<" loscom_min="<<loscom_min_<<" loscom_max="<<loscom_max_<<" Mpc "<<endl;
     240 }
     241
     242 // Fill the corresponding vectors
     243 for(double z=0.; ; z+=zinc) {
     244   double dlc = cosmo_->Dloscom(z);
     245   if(dlc<loscom_min_) {zred_.resize(0); loscom_.resize(0);}
     246   zred_.push_back(z);
     247   loscom_.push_back(dlc);
     248   z += zinc;
     249   if(dlc>loscom_max_) break; // on break apres avoir stoque un dlc>dlcmax
     250 }
     251
     252 long n = zred_.size();
     253 if(lp_>0) {
     254   cout<<"...n="<<n;
     255   if(n>0) cout<<" z="<<zred_[0]<<" -> d="<<loscom_[0];
     256   if(n>1) cout<<" , z="<<zred_[n-1]<<" -> d="<<loscom_[n-1];
     257   cout<<endl;
     258 }
     259
     260 return n;
     261}
    166262
    167263//-------------------------------------------------------
     
    323419
    324420 // --- On remplit avec une realisation
    325  if(lp_>0) cout<<"...before Fourier realization filling ---"<<endl;
     421 if(lp_>0) cout<<"...before Fourier realization filling"<<endl;
    326422 T_(0,0,0) = complex<r_8>(0.);  // on coupe le continue et on l'initialise
    327423 long lmod = Nx_/10; if(lmod<1) lmod=1;
     
    529625
    530626//-------------------------------------------------------------------
     627void GeneFluct3D::ApplyGrowthFactor(long npoints)
     628// Apply Growth to real space
     629// Using the correspondance between redshift and los comoving distance
     630// describe in vector "zred_" "loscom_"
     631{
     632 if(npoints<3) npoints = zred_.size();
     633 if(lp_>0) cout<<"--- ApplyGrowthFactor ---  npoints="<<npoints<<endl;
     634 check_array_alloc();
     635
     636 if(growth_ == NULL) {
     637   cout<<"GeneFluct3D::ApplyGrowthFactor_Error: set GrowthFactor first"<<endl;
     638   throw ParmError("GeneFluct3D::ApplyGrowthFactor_Error: set GrowthFactor first");
     639 }
     640
     641 long n = zred_.size();
     642 InverseFunc invfun(zred_,loscom_);
     643 vector<double> invlos;
     644 invfun.ComputeParab(npoints,invlos);
     645
     646 InterpFunc interpinv(invfun.YMin(),invfun.YMax(),invlos);
     647 unsigned short ok;
     648
     649 //CHECK: Histo hgr(0.9*zred_[0],1.1*zred_[n-1],1000);
     650 for(long i=0;i<Nx_;i++) {
     651   double dx2 = xobs_[0] - i*Dx_; dx2 *= dx2;
     652   for(long j=0;j<Ny_;j++) {
     653     double dy2 = xobs_[1] - j*Dy_; dy2 *= dy2;
     654     for(long l=0;l<Nz_;l++) {
     655       double dz2 = xobs_[2] - l*Dz_; dz2 *= dz2;
     656       dz2 = sqrt(dx2+dy2+dz2);
     657       double z = interpinv(dz2);
     658       //CHECK: hgr.Add(z);
     659       double dzgr = (*growth_)(z);   // interpolation par morceau
     660       //double dzgr = growth_->Linear(z,ok);  // interpolation lineaire
     661       //double dzgr = growth_->Parab(z,ok);  // interpolation parabolique
     662       int_8 ip = IndexR(i,j,l);
     663       data_[ip] *= dzgr;
     664     }
     665   }
     666 }
     667
     668 //CHECK: {POutPersist pos("applygrowth.ppf"); string tag="hgr"; pos.PutObject(hgr,tag);}
     669
     670}
     671
     672//-------------------------------------------------------------------
    531673void GeneFluct3D::ComputeReal(void)
    532674// Calcule une realisation dans l'espace reel
Note: See TracChangeset for help on using the changeset viewer.