Changeset 3806 in Sophya for trunk/Cosmo/SimLSS/cmvginit3d.cc


Ignore:
Timestamp:
Jul 24, 2010, 6:15:07 PM (15 years ago)
Author:
cmv
Message:

suite de la mise au point pour lecture fichiers CAMB, cmv 24/07/2010

File:
1 edited

Legend:

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

    r3805 r3806  
    2020#include "geneutils.h"
    2121#include "genefluct3d.h"
     22
     23string decodecambarg(string arg,double& h, double& z);
    2224
    2325void usage(void);
     
    3638     <<" -z nz,dz : size along z axis (redshift axis, npix,Mpc)"<<endl
    3739     <<" -Z zref : redshift for the center of the simulation cube"<<endl
     40     <<" -f cambspec.dat,h100tab,ztab : use CAMB file (def: Eisenstein spectrum)"<<endl
    3841     <<" -1 : compute 1D spectrum (default: no)"<<endl
    3942     <<" -2 : compute 2D spectrum (default: no)"<<endl
     
    6972 unsigned short flat = 0;
    7073 double ob0 = 0.0444356;
    71  double h100=0.71, om0=0.267804, or0=7.9e-05, ol0=0.73,w0=-1.;
     74 double h100=0.71, om0=0.267804, or0=7.9e-05, ol0=0.73, w0=-1.;
    7275 double zref = 0.5;
    7376 double perc=0.01,dzinc=-1.,dzmax=-1.; unsigned short glorder=4;
     
    7881 double sigmaR = 1.;
    7982
    80  double kmin=1e-5,kmax=1000.;
    81  int npt = 10000;
    82  double lkmin=log10(kmin), lkmax=log10(kmax);
     83 double kmin=1e-4,kmax=100.;
     84 int npt = 1000;
    8385 double eps=1.e-3;
     86
     87 // *** Spectrum read from CAMB file
     88 string cambfread = "";
    8489
    8590 // *** type de generation
     
    115120 // --- Decodage des arguments
    116121 char c;
    117  while((c = getopt(narg,arg,"haG:F:x:y:z:Z:128:v:n:CO:So:VT:")) != -1) {
     122 while((c = getopt(narg,arg,"haG:F:x:y:z:Z:128:v:n:CO:So:VT:f:")) != -1) {
    118123  int nth = 0;
    119124  switch (c) {
     
    175180    nthread = (nth<1)? 0: nth;
    176181    break;
     182  case 'f' :
     183    cambfread = optarg;
     184    break;
    177185  case 'h' :
    178186  default :
     
    189197 cout<<"zref="<<zref<<endl;
    190198 cout<<"nx="<<nx<<" dx="<<dx<<" ny="<<ny<<" dy="<<dy<<" nz="<<nz<<" dz="<<dz<<endl;
    191  cout<<"kmin="<<kmin<<" ("<<lkmin<<"), kmax="<<kmax<<" ("<<lkmax<<") Mpc^-1"<<", npt="<<npt<<endl;
     199 cout<<"kmin="<<kmin<<" ("<<log10(kmin)<<"), kmax="<<kmax<<" ("<<log10(kmax)<<") Mpc^-1"<<", npt="<<npt<<endl;
    192200 cout<<"Filter by pixel = "<<filter_by_pixel<<endl;
    193201 if(comptransveloc) cout<<"Tansverse velocity generation requested"<<endl;
     202 if(cambfread.size()>0) cout<<"use CAMB file: cambfread="<<cambfread<<endl;
    194203 cout<<"R="<<R<<" Rg="<<Rg<<" Mpc, sigmaR="<<sigmaR<<endl;
    195204 cout<<"Use_growth_factor = "<<use_growth_factor<<endl;
     
    216225
    217226 //-----------------------------------------------------------------
    218  cout<<endl<<"\n--- Create Spectrum"<<endl;
    219 
    220  InitialPowerLaw pkini(ns,as);
    221 
    222  TransfertEisenstein tf(h100,om0-ob0,ob0,T_CMB_Par,false);
    223  TransfertEisenstein tfnos(h100,om0-ob0,ob0,T_CMB_Par,false);
    224    tfnos.SetNoOscEnv(2);
     227 cout<<endl<<"\n--- Create GrowthFactor"<<endl;
    225228
    226229 GrowthEisenstein growth(om0,ol0);
     
    229232 cout<<"...Growth factor at z="<<zref<<" = "<<growth_at_z<<endl;
    230233
    231  PkSpecCalc pkz(pkini,tf,growth,zref);
     234 //-----------------------------------------------------------------
     235 cout<<endl<<"\n--- Create Spectrum"<<endl;
     236
     237 InitialPowerLaw pkini(ns,as);
     238
     239 TransfertEisenstein tfnos(h100,om0-ob0,ob0,T_CMB_Par,false);
     240   tfnos.SetNoOscEnv(2);
     241 TransfertEisenstein tf(h100,om0-ob0,ob0,T_CMB_Par,false);
     242
    232243 PkSpecCalc pkznos(pkini,tfnos,growth,zref);
    233 
    234  //-----------------------------------------------------------------
    235  pkz.SetZ(0.);
     244 PkSpectrum* pkz = NULL;
     245 if(cambfread.size()>0) {  // read pk in CAMB file
     246   double h100tab, ztab;
     247   string fn = decodecambarg(cambfread,h100tab,ztab);
     248   if(h100tab<=0.) h100tab = h100;
     249   PkTabulate* pkzt = new PkTabulate;
     250   pkzt->ReadCAMB(fn,h100tab,ztab);
     251   pkzt->SetGrowthFactor(&growth);
     252   pkzt->SetZ(zref);
     253   pkz = pkzt;
     254   // change k limits
     255   kmin = pkzt->KMin();
     256   kmax = pkzt->KMax();
     257   cout<<"Change k limits to kmin="<<kmin<<" kmax="<<kmax<<endl;
     258 } else {   // use Eisenstein pk
     259   PkSpecCalc* pkze = new PkSpecCalc(pkini,tf,growth,zref);
     260   pkz = pkze;
     261 }
     262
     263 //-----------------------------------------------------------------
     264 cout<<endl<<"\n--- Normalize Spectrum"<<endl;
     265
     266 pkz->SetZ(0.);
    236267 pkznos.SetZ(0.);
    237  cout<<endl<<"\n--- Compute variance for top-hat R="<<R<<" at z="<<pkz.GetZ()<<endl;
    238  VarianceSpectrum varpk_th(pkz,R,VarianceSpectrum::TOPHAT);
    239  double kfind_th = varpk_th.FindMaximum(kmin,kmax,eps);
    240  double pkmax_th = varpk_th(kfind_th);
    241  cout<<"kfind_th = "<<kfind_th<<" ("<<log10(kfind_th)<<"), integrand="<<pkmax_th<<endl;
    242  double k1=kmin, k2=kmax;
    243  int rc = varpk_th.FindLimits(pkmax_th/1.e4,k1,k2,eps);
    244  cout<<"limit_th: rc="<<rc<<" : "<<k1<<" ("<<log10(k1)<<") , "
    245      <<k2<<" ("<<log10(k2)<<")"<<endl;
    246 
    247  double ldlk = (log10(k2)-log10(k1))/npt;
    248  varpk_th.SetInteg(0.01,ldlk,-1.,4);
    249  double sr2 = varpk_th.Variance(k1,k2);
    250  cout<<"varpk_th="<<sr2<<"  ->  sigma="<<sqrt(sr2)<<endl;
    251 
    252  double normpkz = sigmaR*sigmaR/sr2;
    253  pkz.SetScale(normpkz);
    254  pkznos.SetScale(normpkz);
    255  cout<<"Spectrum normalisation = "<<pkz.GetScale()<<endl;
     268
     269 double normpkz[2] = {0.,0.};
     270 for(int i=0;i<2;i++) {
     271   PkSpectrum* pkvar = NULL; string nam = "";
     272   if(i==0) pkvar = pkz; else {pkvar = &pkznos; nam = "NoOsc";}
     273   cout<<endl<<"\n--- Compute variance for Pk "<<nam<<" with top-hat R="<<R<<" at z="<<pkvar->GetZ()<<endl;
     274   VarianceSpectrum varpk_th(*pkvar,R,VarianceSpectrum::TOPHAT);
     275   double kfind_th = varpk_th.FindMaximum(kmin,kmax,eps);
     276   double pkmax_th = varpk_th(kfind_th);
     277   cout<<"kfind_th = "<<kfind_th<<" ("<<log10(kfind_th)<<"), integrand="<<pkmax_th<<endl;
     278   double k1=kmin, k2=kmax;
     279   int rc = varpk_th.FindLimits(pkmax_th/1.e4,k1,k2,eps);
     280   cout<<"limit_th: rc="<<rc<<" : "<<k1<<" ("<<log10(k1)<<") , "
     281       <<k2<<" ("<<log10(k2)<<")"<<endl;
     282   double ldlk = (log10(k2)-log10(k1))/npt;
     283   varpk_th.SetInteg(0.01,ldlk,-1.,4);
     284   double sr2 = varpk_th.Variance(k1,k2);
     285   normpkz[i] = sigmaR*sigmaR/sr2;
     286   cout<<"varpk_th="<<sr2<<"  ->  sigma="<<sqrt(sr2)<<" normpkz="<<normpkz[i]<<endl;
     287 }
     288 cout<<endl;
     289
     290 if(cambfread.size()>0) {
     291   pkz->SetScale(1.);
     292   pkznos.SetScale(normpkz[1]);
     293   cout<<"Warning: CAMB spectrum, no normalisation applied, scale="<<pkz->GetScale()<<endl;
     294 } else {
     295   pkz->SetScale(normpkz[0]);
     296   pkznos.SetScale(normpkz[0]);
     297   cout<<"Spectrum normalisation (osc+noosc), scale = "<<pkz->GetScale()<<endl;
     298 }
     299
    256300 {
    257  Histo hpkz0(lkmin,lkmax,npt); hpkz0.ReCenterBin();
    258  FuncToHisto(pkz,hpkz0,true);
     301 Histo hpkz0(log10(kmin),log10(kmax),npt); hpkz0.ReCenterBin();
     302 FuncToHisto(*pkz,hpkz0,true);
    259303 posobs.PutObject(hpkz0,"hpkz0");
    260304 Histo hpkz0nos(hpkz0);
     
    263307 }
    264308
    265  pkz.SetZ(zref);
     309 pkz->SetZ(zref);
    266310 pkznos.SetZ(zref);
     311
    267312 {
    268  Histo hpkz(lkmin,lkmax,npt); hpkz.ReCenterBin();
    269  FuncToHisto(pkz,hpkz,true);
     313 Histo hpkz(log10(kmin),log10(kmax),npt); hpkz.ReCenterBin();
     314 FuncToHisto(*pkz,hpkz,true);
    270315 posobs.PutObject(hpkz,"hpkz");
    271316 Histo hpkznos(hpkz);
     
    275320
    276321 //-----------------------------------------------------------------
    277  cout<<endl<<"\n--- Compute variance for Pk at z="<<pkz.GetZ()<<endl;
    278  VarianceSpectrum varpk_int(pkz,R,VarianceSpectrum::NOFILTER);
     322 cout<<endl<<"\n--- Compute variance for Pk at z="<<pkz->GetZ()<<endl;
     323 VarianceSpectrum varpk_int(*pkz,R,VarianceSpectrum::NOFILTER);
    279324 double kfind_int = varpk_int.FindMaximum(kmin,kmax,eps);
    280325 double pkmax_int = varpk_int(kfind_int);
     
    325370
    326371 //-----------------------------------------------------------------
    327  cout<<"\n--- Computing spectra variance up to Kmax at z="<<pkz.GetZ()<<endl;
     372 cout<<"\n--- Computing spectra variance up to Kmax at z="<<pkz->GetZ()<<endl;
    328373 // En fait on travaille sur un cube inscrit dans la sphere de rayon kmax:
    329374 // sphere: Vs = 4Pi/3 k^3 , cube inscrit (cote k*sqrt(2)): Vc = (k*sqrt(2))^3
     
    339384 //-----------------------------------------------------------------
    340385 cout<<"\n--- Computing a realization in Fourier space"<<endl;
    341  if(use_growth_factor>0) pkz.SetZ(0.); else pkz.SetZ(zref);
    342  cout<<"Power spectrum set at redshift: "<<pkz.GetZ()<<endl;
    343  fluct3d.ComputeFourier(pkz);
     386 if(use_growth_factor>0) pkz->SetZ(0.); else pkz->SetZ(zref);
     387 cout<<"Power spectrum set at redshift: "<<pkz->GetZ()<<endl;
     388 fluct3d.ComputeFourier(*pkz);
    344389 fluct3d.NTupleCheck(posobs,string("ntpkgen"),ntnent);
    345390 PrtTim(">>>> End Computing a realization in Fourier space");
     
    411456 //-----------------------------------------------------------------
    412457 cout<<"\n--- Computing a realization in real space"<<endl;
     458 double vdum1,vdum2;
    413459 fluct3d.ComputeReal();
    414  double rmin,rmax; fluct3d.MinMax(rmin,rmax);
    415  cout<<"rgen.Min = "<<rmin<<" , Max="<<rmax<<endl;
     460 fluct3d.MinMax(vdum1,vdum2);
     461 fluct3d.MeanSigma2(vdum1,vdum2);
    416462 fluct3d.NTupleCheck(posobs,string("ntreal"),ntnent);
    417463 PrtTim(">>>> End Computing a realization in real space");
     
    421467   cout<<"...D(z=0)="<<growth(0.)<<"  D(z="<<zref<<")="<<growth(zref)<<endl;
    422468   fluct3d.ApplyGrowthFactor(use_growth_factor);
    423    fluct3d.MinMax(rmin,rmax);
    424    cout<<"rgen.Min = "<<rmin<<" , Max="<<rmax<<endl;
     469   fluct3d.MinMax(vdum1,vdum2);
     470   fluct3d.MeanSigma2(vdum1,vdum2);
    425471   fluct3d.NTupleCheck(posobs,string("ntgrow"),ntnent);
    426472   PrtTim(">>>> End Applying growth factor");
    427473 }
    428 
    429  int_8 nm;
    430  double rmref,rs2ref;
    431  cout<<"\n--- Computing reference variance in real space"<<endl;
    432  nm = fluct3d.MeanSigma2(rmref,rs2ref);
    433  cout<<" rs2ref= "<<rs2ref<<" , rmref="<<rmref<<" ("<<nm<<")"<<endl;
    434  PrtTim(">>>> End Computing reference variance in real space");
    435474
    436475 if(whattowrt[1]&1) {
     
    561600   cout<<"\n--- Computing a realization in real space for Transverse velocity"<<endl;
    562601   fluct3d.ComputeReal();
    563    double rmin,rmax; fluct3d.MinMax(rmin,rmax);
    564    cout<<"rgen.Min = "<<rmin<<" , Max="<<rmax<<endl;
     602   fluct3d.MinMax(vdum1,vdum2);
     603   fluct3d.MeanSigma2(vdum1,vdum2);
    565604   fluct3d.NTupleCheck(posobs,string("nvreal"),ntnent);
    566605   PrtTim(">>>> End Computing a realization in real space");
    567606
    568607    if(use_growth_factor>0) {
    569       cout<<"\n--- Apply Growth factor"<<endl;
     608      cout<<"\n--- Apply Growth factor for transverse velocity"<<endl;
    570609      cout<<"...D(z=0)="<<growth(0.)<<"  D(z="<<zref<<")="<<growth(zref)<<endl;
    571610      fluct3d.ApplyVelLosGrowthFactor(use_growth_factor);
    572       fluct3d.MinMax(rmin,rmax);
    573       cout<<"rgen.Min = "<<rmin<<" , Max="<<rmax<<endl;
     611      fluct3d.MinMax(vdum1,vdum2);
     612      fluct3d.MeanSigma2(vdum1,vdum2);
    574613      fluct3d.NTupleCheck(posobs,string("nvgrow"),ntnent);
    575614      PrtTim(">>>> End Applying growth factor");
    576615    }
    577 
    578     int_8 nmv;
    579     double vmref,vs2ref;
    580     cout<<"\n--- Computing reference variance in real space"<<endl;
    581     nmv = fluct3d.MeanSigma2(vmref,vs2ref);
    582     cout<<" vs2ref= "<<vs2ref<<" , vmref="<<vmref<<" ("<<nmv<<")"<<endl;
    583     PrtTim(">>>> End Computing reference variance in real space");
    584616
    585617    if(whattowrt[1]&1) {
     
    610642 dvl("s8") = sigmaR;
    611643 dvl("Dtype") = (int_4)use_growth_factor; dvl("Pxfilt") = (int_4)filter_by_pixel;
     644 if(cambfread.size()>0) dvl("fCAMB") = cambfread;
    612645 posobs.PutObject(dvl,"siminfo");
    613646 }
    614647
    615648 delete RandGen;
     649 if(pkz != NULL) delete pkz;
    616650 PrtTim(">>>> End Of Job");
    617651
     
    634668}
    635669
     670#include "strutilxx.h"
     671string decodecambarg(string arg,double& h, double& z)
     672// - decode argument for CAMB generation:
     673// input: arg = "cambfilename,h100tab,ztab"
     674// output: h = h100 use to generate CAMB file
     675//         z = redshift use to generate CAMB file
     676// return: CAMB file name
     677{
     678  h = -1.;
     679  z = 0.;
     680  vector<string> vs;
     681  FillVStringFrString(arg,vs,',');
     682  if(vs.size()>1) h = atof(vs[1].c_str());
     683  if(vs.size()>2) z = atof(vs[2].c_str());
     684  cout<<"decodecambarg: "<<arg<<" fn=\""<<vs[0]<<"\" h="<<h<<" z="<<z<<endl;
     685  return vs[0];
     686}
Note: See TracChangeset for help on using the changeset viewer.