Changeset 3805 in Sophya for trunk/Cosmo/SimLSS/pkspectrum.cc
- Timestamp:
- Jul 24, 2010, 12:01:34 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Cosmo/SimLSS/pkspectrum.cc
r3802 r3805 16 16 17 17 /////////////////////////////////////////////////////////// 18 //******************** Initial Spectrum******************//19 /////////////////////////////////////////////////////////// 20 21 Initial Spectrum::InitialSpectrum(double n,double a)18 //******************** InitialPowerLaw ******************// 19 /////////////////////////////////////////////////////////// 20 21 InitialPowerLaw::InitialPowerLaw(double n,double a) 22 22 : n_(n), A_(a) 23 23 { 24 24 } 25 25 26 Initial Spectrum::InitialSpectrum(InitialSpectrum& pkinf)26 InitialPowerLaw::InitialPowerLaw(InitialPowerLaw& pkinf) 27 27 : n_(pkinf.n_), A_(pkinf.A_) 28 28 { 29 29 } 30 30 31 Initial Spectrum::~InitialSpectrum(void)31 InitialPowerLaw::~InitialPowerLaw(void) 32 32 { 33 33 } … … 298 298 : kmin_(1.) , kmax_(-1.) , interptyp_(0) 299 299 { 300 k_.resize(0); 301 tf_.resize(0); 300 302 } 301 303 … … 331 333 char *line = new char[lenline]; 332 334 333 int nread = 0;335 k_.resize(0); tf_.resize(0); 334 336 double tmax = -1.; 335 337 while ( fgets(line,lenline,file) != NULL ) { … … 341 343 k_.push_back(k); 342 344 tf_.push_back(tf); 343 nread++;344 345 } 345 346 346 cout<<"TransfertTabulate::ReadCMBFast: nread="<< nread<<" tf_max="<<tmax<<endl;347 cout<<"TransfertTabulate::ReadCMBFast: nread="<<tf_.size()<<" tf_max="<<tmax<<endl; 347 348 delete [] line; 348 if( nread==0) return nread;349 if(tf_.size()==0) return (int)tf_.size(); 349 350 350 351 for(unsigned int i=0;i<tf_.size();i++) tf_[i] /= tmax; 351 352 352 return nread; 353 } 353 return (int)tf_.size(); 354 } 355 356 int 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 354 386 355 387 /////////////////////////////////////////////////////////// 356 388 //********************* GrowthFactor ********************// 389 /////////////////////////////////////////////////////////// 390 double 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 ********************// 357 398 /////////////////////////////////////////////////////////// 358 399 359 400 // From Eisenstein & Hu ApJ 496:605-614 1998 April 1 360 401 // Pour avoir D(z) = 1/(1+z) faire: OmegaMatter0=1 OmegaLambda0=0 361 Growth Factor::GrowthFactor(double OmegaMatter0,double OmegaLambda0)402 GrowthEisenstein::GrowthEisenstein(double OmegaMatter0,double OmegaLambda0) 362 403 : O0_(OmegaMatter0) , Ol_(OmegaLambda0) 363 404 { 364 405 if(OmegaMatter0==0.) { 365 cout<<"Growth Factor::GrowthFactor: Error bad OmegaMatter0 value : "<<OmegaMatter0<<endl;366 throw ParmError("Growth Factor::GrowthFactor: Error badOmegaMatter0 value");367 } 368 } 369 370 Growth Factor::GrowthFactor(GrowthFactor& d1)406 cout<<"GrowthEisenstein::GrowthEisenstein: Error bad OmegaMatter0 value : "<<OmegaMatter0<<endl; 407 throw ParmError("GrowthEisenstein::GrowthEisenstein: Error badOmegaMatter0 value"); 408 } 409 } 410 411 GrowthEisenstein::GrowthEisenstein(GrowthEisenstein& d1) 371 412 : O0_(d1.O0_) , Ol_(d1.Ol_) 372 413 { 373 414 } 374 415 375 Growth Factor::~GrowthFactor(void)376 { 377 } 378 379 double Growth Factor::operator() (double z)416 GrowthEisenstein::~GrowthEisenstein(void) 417 { 418 } 419 420 double GrowthEisenstein::operator() (double z) 380 421 // see Formulae A4 + A5 + A6 page 614 381 422 { … … 399 440 } 400 441 401 double Growth Factor::DsDz(double z,double dzinc)442 double GrowthEisenstein::DsDz(double z,double dzinc) 402 443 // y-y0 = a*(x-x0)^2 + b*(x-x0) 403 444 // dy = a*dx^2 + b*dx avec dx = x-x0 … … 405 446 { 406 447 if(z<0. || dzinc<=0.) { 407 cout<<"Growth Factor::DsDz: z<0 or dzinc<=0. !"<<endl;408 throw ParmError("Growth Factor::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. !"); 409 450 } 410 451 … … 431 472 } 432 473 433 void Growth Factor::SetParTo(double OmegaMatter0,double OmegaLambda0)474 void GrowthEisenstein::SetParTo(double OmegaMatter0,double OmegaLambda0) 434 475 { 435 476 if(OmegaMatter0>0.) O0_ = OmegaMatter0; … … 437 478 } 438 479 439 bool Growth Factor::SetParTo(double OmegaMatter0)480 bool GrowthEisenstein::SetParTo(double OmegaMatter0) 440 481 // idem precedent sans changer OmegaLambda0 441 482 { … … 447 488 448 489 /////////////////////////////////////////////////////////// 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 493 PkSpectrum::PkSpectrum(void) 494 : zref_(0.) , scale_(1.) , typspec_(PK) 495 { 496 } 497 498 PkSpectrum::PkSpectrum(PkSpectrum& pk) 499 : zref_(pk.zref_) , scale_(pk.scale_) , typspec_(pk.typspec_) 500 { 501 } 502 503 504 /////////////////////////////////////////////////////////// 505 //********************** PkSpecCalc *********************// 506 /////////////////////////////////////////////////////////// 507 508 PkSpecCalc::PkSpecCalc(InitialSpectrum& pkinf,TransfertFunction& tf,GrowthFactor& d1,double zref) 509 : pkinf_(pkinf) , tf_(tf) , d1_(d1) 510 { 511 zref_ = zref; 512 } 513 514 PkSpecCalc::PkSpecCalc(PkSpecCalc& pkz) 515 : pkinf_(pkz.pkinf_) , tf_(pkz.tf_) , d1_(pkz.d1_) 516 { 517 } 518 519 PkSpecCalc::~PkSpecCalc(void) 520 { 521 } 522 523 double PkSpecCalc::operator() (double k) 524 { 525 return (*this)(k,zref_); 526 } 527 528 double PkSpecCalc::operator() (double k,double z) 467 529 { 468 530 double tf = tf_(k); 469 531 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 544 PkTabulate::PkTabulate(void) 545 : kmin_(1.) , kmax_(-1.) , interptyp_(0) 546 { 547 k_.resize(0); 548 pk_.resize(0); 549 } 550 551 PkTabulate::PkTabulate(PkTabulate& pkz) 552 : kmin_(pkz.kmin_) , kmax_(pkz.kmax_) , interptyp_(pkz.interptyp_) , k_(pkz.k_) , pk_(pkz.pk_) 553 { 554 } 555 556 557 PkTabulate::~PkTabulate(void) 558 { 559 } 560 561 void 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 568 double 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 575 double 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 581 int 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 611 PkEisenstein::PkEisenstein(InitialPowerLaw& pkinf,TransfertEisenstein& tf,GrowthEisenstein& d1,double zref) 612 : pkinf_(pkinf) , tf_(tf) , d1_(d1) 613 { 614 zref_ = zref; 615 } 616 617 PkEisenstein::PkEisenstein(PkEisenstein& pkz) 618 : pkinf_(pkz.pkinf_) , tf_(pkz.tf_) , d1_(pkz.d1_) 619 { 620 } 621 622 PkEisenstein::~PkEisenstein(void) 623 { 624 } 625 626 double PkEisenstein::operator() (double k) 496 627 { 497 628 return (*this)(k,zref_); 498 629 } 499 630 500 double PkSpectrumZ::operator() (double k,double z) 501 { 631 double PkEisenstein::operator() (double k,double z) 632 { 633 double tf = tf_(k); 634 double pkinf = pkinf_(k); 502 635 double d1 = d1_(z); 503 636 504 double v = pk 0_(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); 506 639 507 640 return scale_ * v; 508 641 } 509 510 642 511 643
Note:
See TracChangeset
for help on using the changeset viewer.