Changeset 3805 in Sophya for trunk/Cosmo/SimLSS/pkspectrum.cc


Ignore:
Timestamp:
Jul 24, 2010, 12:01:34 AM (15 years ago)
Author:
cmv
Message:

Refonte totale de la structure des classes InitialSpectrum, TransfertFunction, GrowthFactor, PkSpectrum et classes tabulate pour lecture des fichiers CAMB, cmv 24/07/2010

File:
1 edited

Legend:

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

    r3802 r3805  
    1616
    1717///////////////////////////////////////////////////////////
    18 //******************** InitialSpectrum ******************//
    19 ///////////////////////////////////////////////////////////
    20 
    21 InitialSpectrum::InitialSpectrum(double n,double a)
     18//******************** InitialPowerLaw ******************//
     19///////////////////////////////////////////////////////////
     20
     21InitialPowerLaw::InitialPowerLaw(double n,double a)
    2222  : n_(n), A_(a)
    2323{
    2424}
    2525
    26 InitialSpectrum::InitialSpectrum(InitialSpectrum& pkinf)
     26InitialPowerLaw::InitialPowerLaw(InitialPowerLaw& pkinf)
    2727  : n_(pkinf.n_), A_(pkinf.A_)
    2828{
    2929}
    3030
    31 InitialSpectrum::~InitialSpectrum(void)
     31InitialPowerLaw::~InitialPowerLaw(void)
    3232{
    3333}
     
    298298: kmin_(1.) , kmax_(-1.) , interptyp_(0)
    299299{
     300  k_.resize(0);
     301  tf_.resize(0);
    300302}
    301303
     
    331333 char *line = new char[lenline];
    332334
    333  int nread = 0;
     335 k_.resize(0); tf_.resize(0);
    334336 double tmax = -1.;
    335337 while ( fgets(line,lenline,file) != NULL ) {
     
    341343   k_.push_back(k);
    342344   tf_.push_back(tf);
    343    nread++;
    344345 }
    345346
    346  cout<<"TransfertTabulate::ReadCMBFast: nread="<<nread<<" tf_max="<<tmax<<endl;
     347 cout<<"TransfertTabulate::ReadCMBFast: nread="<<tf_.size()<<" tf_max="<<tmax<<endl;
    347348 delete [] line;
    348  if(nread==0) return nread;
     349 if(tf_.size()==0) return (int)tf_.size();
    349350
    350351 for(unsigned int i=0;i<tf_.size();i++) tf_[i] /= tmax;
    351352
    352  return nread;
    353 }
     353 return (int)tf_.size();
     354}
     355
     356int TransfertTabulate::ReadCAMB(string filename, double h100)
     357{
     358 FILE *file = fopen(filename.c_str(),"r");
     359 if(file==NULL) return -1;
     360 cout<<"TransfertTabulate::ReadCAMB: fn="<<filename<<" h100="<<h100<<endl;
     361
     362 const int lenline = 512;
     363 char *line = new char[lenline];
     364
     365 k_.resize(0); tf_.resize(0);
     366 double tmax = -1.;
     367 while ( fgets(line,lenline,file) != NULL ) {
     368   double k,tcdm,tbar,tph,trel,tnu,ttot, tf;
     369   sscanf(line,"%lf %lf %lf %lf %lf %lf %lf",&k,&tcdm,&tbar,&tph,&trel,&tnu,&ttot);
     370   k *= h100;     // convert h Mpc^-1  ->  Mpc^-1
     371   tf = ttot;
     372   if(tf>tmax) tmax = tf;
     373   k_.push_back(k);
     374   tf_.push_back(tf);
     375 }
     376
     377 cout<<"TransfertTabulate::ReadCAMB nread="<<tf_.size()<<" tf_max="<<tmax<<endl;
     378 delete [] line;
     379 if(tf_.size()==0) return (int)tf_.size();
     380
     381 for(unsigned int i=0;i<tf_.size();i++) tf_[i] /= tmax;
     382
     383 return (int)tf_.size();
     384}
     385
    354386
    355387///////////////////////////////////////////////////////////
    356388//********************* GrowthFactor ********************//
     389///////////////////////////////////////////////////////////
     390double GrowthFactor::DsDz(double z, double)
     391{
     392  cout<<"Error: GrowthFactor::DsDz not implemented"<<endl;
     393  throw AllocationError("Error: GrowthFactor::DsDz not implemented");
     394}
     395
     396///////////////////////////////////////////////////////////
     397//********************* GrowthEisenstein ********************//
    357398///////////////////////////////////////////////////////////
    358399
    359400// From Eisenstein & Hu ApJ 496:605-614 1998 April 1
    360401// Pour avoir D(z) = 1/(1+z) faire: OmegaMatter0=1 OmegaLambda0=0
    361 GrowthFactor::GrowthFactor(double OmegaMatter0,double OmegaLambda0)
     402GrowthEisenstein::GrowthEisenstein(double OmegaMatter0,double OmegaLambda0)
    362403  : O0_(OmegaMatter0) , Ol_(OmegaLambda0)
    363404{
    364405  if(OmegaMatter0==0.) {
    365     cout<<"GrowthFactor::GrowthFactor: Error bad OmegaMatter0  value : "<<OmegaMatter0<<endl;
    366     throw ParmError("GrowthFactor::GrowthFactor: Error badOmegaMatter0  value");
    367   }
    368 }
    369 
    370 GrowthFactor::GrowthFactor(GrowthFactor& d1)
     406    cout<<"GrowthEisenstein::GrowthEisenstein: Error bad OmegaMatter0  value : "<<OmegaMatter0<<endl;
     407    throw ParmError("GrowthEisenstein::GrowthEisenstein: Error badOmegaMatter0  value");
     408  }
     409}
     410
     411GrowthEisenstein::GrowthEisenstein(GrowthEisenstein& d1)
    371412  : O0_(d1.O0_) , Ol_(d1.Ol_)
    372413{
    373414}
    374415
    375 GrowthFactor::~GrowthFactor(void)
    376 {
    377 }
    378 
    379 double GrowthFactor::operator() (double z)
     416GrowthEisenstein::~GrowthEisenstein(void)
     417{
     418}
     419
     420double GrowthEisenstein::operator() (double z)
    380421// see Formulae A4 + A5 + A6 page 614
    381422{
     
    399440}
    400441
    401 double GrowthFactor::DsDz(double z,double dzinc)
     442double GrowthEisenstein::DsDz(double z,double dzinc)
    402443// y-y0 = a*(x-x0)^2 + b*(x-x0)
    403444// dy = a*dx^2 + b*dx   avec  dx = x-x0
     
    405446{
    406447 if(z<0. || dzinc<=0.) {
    407    cout<<"GrowthFactor::DsDz: z<0 or dzinc<=0. !"<<endl;
    408    throw ParmError("GrowthFactor::DsDz: z<0 or dzinc<=0. !");
     448   cout<<"GrowthEisenstein::DsDz: z<0 or dzinc<=0. !"<<endl;
     449   throw ParmError("GrowthEisenstein::DsDz: z<0 or dzinc<=0. !");
    409450 }
    410451
     
    431472}
    432473
    433 void GrowthFactor::SetParTo(double OmegaMatter0,double OmegaLambda0)
     474void GrowthEisenstein::SetParTo(double OmegaMatter0,double OmegaLambda0)
    434475{
    435476 if(OmegaMatter0>0.) O0_ = OmegaMatter0;
     
    437478}
    438479
    439 bool GrowthFactor::SetParTo(double OmegaMatter0)
     480bool GrowthEisenstein::SetParTo(double OmegaMatter0)
    440481// idem precedent sans changer OmegaLambda0
    441482{
     
    447488
    448489///////////////////////////////////////////////////////////
    449 //************** PkSpectrum0 et PkSpectrumZ *************//
    450 ///////////////////////////////////////////////////////////
    451 
    452 PkSpectrum0::PkSpectrum0(InitialSpectrum& pkinf,TransfertEisenstein& tf)
    453   : pkinf_(pkinf) , tf_(tf)
    454 {
    455 }
    456 
    457 PkSpectrum0::PkSpectrum0(PkSpectrum0& pk0)
    458   : pkinf_(pk0.pkinf_) , tf_(pk0.tf_)
    459 {
    460 }
    461 
    462 PkSpectrum0::~PkSpectrum0(void)
    463 {
    464 }
    465 
    466 double PkSpectrum0::operator() (double k)
     490//********************** PkSpectrum *********************//
     491///////////////////////////////////////////////////////////
     492
     493PkSpectrum::PkSpectrum(void)
     494  : zref_(0.) , scale_(1.) , typspec_(PK)
     495{
     496}
     497
     498PkSpectrum::PkSpectrum(PkSpectrum& pk)
     499  : zref_(pk.zref_) , scale_(pk.scale_) , typspec_(pk.typspec_)
     500{
     501}
     502
     503
     504///////////////////////////////////////////////////////////
     505//********************** PkSpecCalc *********************//
     506///////////////////////////////////////////////////////////
     507
     508PkSpecCalc::PkSpecCalc(InitialSpectrum& pkinf,TransfertFunction& tf,GrowthFactor& d1,double zref)
     509  : pkinf_(pkinf) , tf_(tf) , d1_(d1)
     510{
     511  zref_ = zref;
     512}
     513
     514PkSpecCalc::PkSpecCalc(PkSpecCalc& pkz)
     515  : pkinf_(pkz.pkinf_) , tf_(pkz.tf_) , d1_(pkz.d1_)
     516{
     517}
     518
     519PkSpecCalc::~PkSpecCalc(void)
     520{
     521}
     522
     523double PkSpecCalc::operator() (double k)
     524{
     525  return (*this)(k,zref_);
     526}
     527
     528double PkSpecCalc::operator() (double k,double z)
    467529{
    468530  double tf = tf_(k);
    469531  double pkinf = pkinf_(k);
    470   return pkinf *tf*tf;
    471 }
    472 
    473 //------------------------------------
    474 PkSpectrumZ::PkSpectrumZ(PkSpectrum0& pk0,GrowthFactor& d1,double zref)
    475   : pk0_(pk0) , d1_(d1) , zref_(zref) , scale_(1.) , typspec_(PK)
    476 {
    477 }
    478 
    479 PkSpectrumZ::PkSpectrumZ(PkSpectrumZ& pkz)
    480   : pk0_(pkz.pk0_) , d1_(pkz.d1_) , zref_(pkz.zref_) , scale_(pkz.scale_) , typspec_(PK)
    481 {
    482 }
    483 
    484 PkSpectrumZ::~PkSpectrumZ(void)
    485 {
    486 }
    487 
    488 void PkSpectrumZ::SetTypSpec(ReturnSpectrum typspec)
    489 // typsec = PK : compute Pk(k)
    490 //        = DELTA : compute Delta^2(k) = k^3*Pk(k)/2Pi^2
    491 {
    492   typspec_ = typspec;
    493 }
    494 
    495 double PkSpectrumZ::operator() (double k)
     532  double d1 = d1_(z);
     533
     534  double v = pkinf * (tf*tf) * (d1*d1);
     535  if(typspec_ == DELTA) v *= k*k*k/(2.*M_PI*M_PI);
     536
     537  return scale_ * v;
     538}
     539
     540///////////////////////////////////////////////////////////
     541//********************** PkTabulate *********************//
     542///////////////////////////////////////////////////////////
     543
     544PkTabulate::PkTabulate(void)
     545: kmin_(1.) , kmax_(-1.) , interptyp_(0)
     546{
     547  k_.resize(0);
     548  pk_.resize(0);
     549}
     550
     551PkTabulate::PkTabulate(PkTabulate& pkz)
     552 : kmin_(pkz.kmin_) , kmax_(pkz.kmax_) , interptyp_(pkz.interptyp_) , k_(pkz.k_) , pk_(pkz.pk_)
     553{
     554}
     555
     556
     557PkTabulate::~PkTabulate(void)
     558{
     559}
     560
     561void PkTabulate ::SetInterpTyp(int typ)
     562// see comment in InterpTab
     563{
     564 if(typ<0) typ=0; else if(typ>2) typ=2;
     565 interptyp_ = typ;
     566}
     567
     568double PkTabulate::operator() (double k)
     569{
     570  double v = InterpTab(k,k_,pk_,interptyp_);
     571  if(typspec_ == DELTA) v *= k*k*k/(2.*M_PI*M_PI);
     572  return scale_ * v;
     573}
     574
     575double PkTabulate::operator() (double k,double z)
     576{
     577  cout<<"Error: PkTabulate::operator(double k,double z) not implemented"<<endl;
     578  throw AllocationError("Error: PkTabulate::operator(double k,double z) not implemented");
     579}
     580
     581int PkTabulate::ReadCAMB(string filename, double h100, double zreftab)
     582{
     583 FILE *file = fopen(filename.c_str(),"r");
     584 if(file==NULL) return -1;
     585 cout<<"PkTabulate::ReadCAMB: fn="<<filename<<" h100="<<h100<<" zreftab = "<<zreftab<<endl;
     586
     587 const int lenline = 512;
     588 char *line = new char[lenline];
     589
     590 k_.resize(0); pk_.resize(0);
     591 while ( fgets(line,lenline,file) != NULL ) {
     592   double k, pk;
     593   sscanf(line,"%lf %lf",&k,&pk);
     594   k *= h100;             // convert h    Mpc^-1  ->  Mpc^-1
     595   pk /= h100*h100*h100;  // convert h^-3 Mpc^3   ->  Mpc^3
     596   k_.push_back(k);
     597   pk_.push_back(pk);
     598 }
     599
     600 SetZ(zreftab);
     601 cout<<"PkTabulate::ReadCAMB nread="<<pk_.size()<<"zref="<<GetZ()<<endl;
     602 delete [] line;
     603
     604 return (int)pk_.size();
     605}
     606
     607///////////////////////////////////////////////////////////
     608//********************* PkEisenstein ********************//
     609///////////////////////////////////////////////////////////
     610
     611PkEisenstein::PkEisenstein(InitialPowerLaw& pkinf,TransfertEisenstein& tf,GrowthEisenstein& d1,double zref)
     612  : pkinf_(pkinf) , tf_(tf) , d1_(d1)
     613{
     614  zref_ = zref;
     615}
     616
     617PkEisenstein::PkEisenstein(PkEisenstein& pkz)
     618  : pkinf_(pkz.pkinf_) , tf_(pkz.tf_) , d1_(pkz.d1_)
     619{
     620}
     621
     622PkEisenstein::~PkEisenstein(void)
     623{
     624}
     625
     626double PkEisenstein::operator() (double k)
    496627{
    497628  return (*this)(k,zref_);
    498629}
    499630
    500 double PkSpectrumZ::operator() (double k,double z)
    501 {
     631double PkEisenstein::operator() (double k,double z)
     632{
     633  double tf = tf_(k);
     634  double pkinf = pkinf_(k);
    502635  double d1 = d1_(z);
    503636
    504   double v = pk0_(k) * d1*d1;
    505   if(typspec_==DELTA) v *= k*k*k/(2.*M_PI*M_PI);
     637  double v = pkinf * (tf*tf) * (d1*d1);
     638  if(typspec_ == DELTA) v *= k*k*k/(2.*M_PI*M_PI);
    506639
    507640  return scale_ * v;
    508641}
    509 
    510642
    511643
Note: See TracChangeset for help on using the changeset viewer.