diff --git a/cpp/ClassEngine.cc b/cpp/ClassEngine.cc index afadf375..82fcd31b 100644 --- a/cpp/ClassEngine.cc +++ b/cpp/ClassEngine.cc @@ -20,6 +20,9 @@ #include #include #include +#include + +//#define DBUG using namespace std; @@ -67,16 +70,26 @@ ClassEngine::ClassEngine(const ClassParams& pars): cl(0),dofree(true){ //prepare fp structure size_t n=pars.size(); // - parser_init(&fc,n,_errmsg); - + parser_init(&fc,n,"pipo",_errmsg); + //config for (size_t i=0;i> _lmax; + } } + cout << __FILE__ << " : using lmax=" << _lmax <0); //input - if (input_init(&fc,&pr,&ba,&th,&pt,&tr,&pm,&sp,&nl,&le,&op,_errmsg) == _FAILURE_) + if (input_init(&fc,&pr,&ba,&th,&pt,&tr,&pm,&sp,&nl,&le,&op,_errmsg) == _FAILURE_) throw invalid_argument(_errmsg); //proetction parametres mal defini @@ -86,7 +99,7 @@ ClassEngine::ClassEngine(const ClassParams& pars): cl(0),dofree(true){ //calcul class computeCls(); - + //cout <<"creating " << sp.ct_size << " arrays" <> _lmax; + } } + cout << __FILE__ << " : using lmax=" << _lmax <0); + + //concatenate both if (parser_cat(&fc_input,&fc_precision,&fc,_errmsg) == _FAILURE_) throw invalid_argument(_errmsg); //parser_free(&fc_input); parser_free(&fc_precision); - + //input - if (input_init(&fc,&pr,&ba,&th,&pt,&tr,&pm,&sp,&nl,&le,&op,_errmsg) == _FAILURE_) + if (input_init(&fc,&pr,&ba,&th,&pt,&tr,&pm,&sp,&nl,&le,&op,_errmsg) == _FAILURE_) throw invalid_argument(_errmsg); //proetction parametres mal defini @@ -134,7 +155,7 @@ ClassEngine::ClassEngine(const ClassParams& pars,const string & precision_file): //calcul class computeCls(); - + //cout <<"creating " << sp.ct_size << " arrays" <& par){ +bool ClassEngine::updateParValues(const std::vector& par){ dofree && freeStructs(); for (size_t i=0;i%s\n",errmsg); @@ -275,7 +304,6 @@ int ClassEngine::class( return _FAILURE_; } - //fprintf(stderr,"%d %e %e %e\n",l,cl[l][0],cl[l][1],cl[l][2]); dofree=true; return _SUCCESS_; @@ -284,35 +312,43 @@ int ClassEngine::class( int ClassEngine::computeCls(){ +#ifdef DBUG + cout <<"call computecls" << endl; //printFC(); - //new call - return this->class_main(&fc,&pr,&ba,&th,&pt,&tr,&pm,&sp,&nl,&le,&op,_errmsg); +#endif + + int status=this->class_main(&fc,&pr,&ba,&th,&pt,&tr,&pm,&sp,&nl,&le,&op,_errmsg); +#ifdef DBUG + cout <<"status=" << status << endl; +#endif + return status; + } int ClassEngine::freeStructs(){ - - + + if (lensing_free(&le) == _FAILURE_) { printf("\n\nError in spectra_free \n=>%s\n",le.error_message); return _FAILURE_; } - + if (nonlinear_free(&nl) == _FAILURE_) { printf("\n\nError in nonlinear_free \n=>%s\n",nl.error_message); return _FAILURE_; } - + if (spectra_free(&sp) == _FAILURE_) { printf("\n\nError in spectra_free \n=>%s\n",sp.error_message); return _FAILURE_; } - + if (primordial_free(&pm) == _FAILURE_) { printf("\n\nError in primordial_free \n=>%s\n",pm.error_message); return _FAILURE_; } - + if (transfer_free(&tr) == _FAILURE_) { printf("\n\nError in transfer_free \n=>%s\n",tr.error_message); return _FAILURE_; @@ -336,46 +372,13 @@ ClassEngine::freeStructs(){ return _SUCCESS_; } -// int -// ClassEngine::l_size(Engine::cltype t){ -// int lmax(-1); - -// switch(t) -// { -// case TT: -// if (sp.has_tt==_TRUE_) lmax=sp.l_size[sp.index_ct_tt]; -// break; -// case TE: -// if (sp.has_te==_TRUE_) lmax=sp.l_size[sp.index_ct_te] ; -// break; -// case EE: -// if (sp.has_ee==_TRUE_) lmax=sp.l_size[sp.index_ct_ee] ; -// break; -// case BB: -// if (sp.has_bb==_TRUE_) lmax=sp.l_size[sp.index_ct_bb] ; -// break; -// case PP: -// if (sp.has_pp==_TRUE_) lmax=sp.l_size[sp.index_ct_pp] ; -// break; -// case TP: -// if (sp.has_tp==_TRUE_) lmax=sp.l_size[sp.index_ct_tp] ; -// break; -// case EP: -// if (sp.has_ep==_TRUE_) lmax=sp.l_size[sp.index_ct_ep] ; -// break; -// } -// return lmax; -// } - - - double ClassEngine::getCl(Engine::cltype t,const long &l){ if (!dofree) throw out_of_range("no Cl available because CLASS failed"); if (output_total_cl_at_l(&sp,&le,&op,static_cast(l),cl) == _FAILURE_){ - cerr << ">>>fail getting Cl type=" << (int)t << " @l=" << l <>>fail getting Cl type=" << (int)t << " @l=" << l <& lvec, //input - std::vector& cltt, - std::vector& clte, - std::vector& clee, +void +ClassEngine::getCls(const std::vector& lvec, //input + std::vector& cltt, + std::vector& clte, + std::vector& clee, std::vector& clbb) { cltt.resize(lvec.size()); clte.resize(lvec.size()); clee.resize(lvec.size()); clbb.resize(lvec.size()); - + for (size_t i=0;i& lvec, //input } } - - -bool -ClassEngine::getLensing(const std::vector& lvec, //input - std::vector& clpp , - std::vector& cltp , + +bool +ClassEngine::getLensing(const std::vector& lvec, //input + std::vector& clpp , + std::vector& cltp , std::vector& clep ){ - + clpp.resize(lvec.size()); cltp.resize(lvec.size()); clep.resize(lvec.size()); - + for (size_t i=0;i& lvec, //input } -void -ClassEngine::writeCls(std::ostream &of,int ttmax){ +double ClassEngine::get_f(double z) +{ + double tau; + int index; + double *pvecback; + //transform redshift in conformal time + background_tau_of_z(&ba,z,&tau); - vector lvec(ttmax-1,1); - lvec[0]=2; - partial_sum(lvec.begin(),lvec.end(),lvec.begin()); + //pvecback must be allocated + pvecback=(double *)malloc(ba.bg_size*sizeof(double)); - vector cltt,clte,clee,clbb,clpp,cltp,clep; - bool hasLensing=false; - try{ - getCls(lvec,cltt,clte,clee,clbb); - hasLensing=getLensing(lvec,clpp,cltp,clep); - } - catch (std::exception &e){ - cout << "GIOSH" << e.what() << endl; - } + //call to fill pvecback + background_at_tau(&ba,tau,ba.long_info,ba.inter_normal, &index, pvecback); - //cout.precision( 16 ); - for (size_t i=0;i +#include +#include +//-------------------- +// C +//---------------- + +using namespace std; +//--------------- +// Constructors -- +//---------------- +Engine::Engine():_lmax(-1) +{ +} +//-------------- +// Destructor -- +//-------------- + +//----------------- +// Member functions -- +//----------------- + +void +Engine::writeCls(std::ostream &of){ + + vector lvec(_lmax-1,1); + lvec[0]=2; + partial_sum(lvec.begin(),lvec.end(),lvec.begin()); + + vector cltt,clte,clee,clbb,clpp,cltp,clep; + bool hasLensing=false; + try{ + getCls(lvec,cltt,clte,clee,clbb); + hasLensing=getLensing(lvec,clpp,cltp,clep); + } + catch (std::exception &e){ + cout << "GIOSH" << e.what() << endl; + } + + cout.precision( 16 ); + for (size_t i=0;i +#include + +class Engine +{ + +public: + + enum cltype {TT=0,EE,TE,BB,PP,TP,EP}; //P stands for phi (lensing potential) + + //constructors + Engine(); + + //pure virtual: + virtual bool updateParValues(const std::vector& cosmopars)=0; + + // units = (micro-K)^2 + virtual void getCls(const std::vector& lVec, //input + std::vector& cltt, + std::vector& clte, + std::vector& clee, + std::vector& clbb)=0; + + + virtual bool getLensing(const std::vector& lVec, //input + std::vector& clpp, + std::vector& cltp, + std::vector& clep)=0; + + + virtual double z_drag() const=0; + virtual double rs_drag() const =0; + + virtual double get_Dv(double z)=0; + + virtual double get_Da(double z)=0; + virtual double get_sigma8(double z)=0; + virtual double get_f(double z)=0; + virtual double get_Fz(double z)=0; + virtual double get_Az(double z)=0; + virtual double get_Hz(double z)=0; + + virtual double getTauReio() const=0; + + // destructor + virtual ~Engine(){}; + + //write Cl model+lensing in ostream + virtual void writeCls(std::ostream &o); + inline int lmax() {return _lmax;} + +protected: + int _lmax; + +}; + +#endif + diff --git a/cpp/README b/cpp/README index 92f3c1e7..b08e8890 100644 --- a/cpp/README +++ b/cpp/README @@ -1,8 +1,9 @@ The C++ wrapper ClassEngine.cc for Class (written by S. Plaszczynski) is distributed together with a test code, testKlass.cc, in which you can write a list of input parameters. This test code can be compiled with (assuming you are already in the directory cpp/): +> c++ -O2 -fopenmp -I../include -c Engine.cc -o Engine.o > c++ -O2 -fopenmp -I../include -c ClassEngine.cc -o ClassEngine.o > c++ -O2 -fopenmp -I../include -c testKlass.cc -o testKlass.o > cd .. -> c++ -O2 -fopenmp build/growTable.o build/dei_rkck.o build/sparse.o build/evolver_rkck.o build/evolver_ndf15.o build/arrays.o build/parser.o build/quadrature.o build/input.o build/background.o build/thermodynamics.o build/perturbations.o build/bessel.o build/transfer.o build/primordial.o build/spectra.o build/trg.o build/nonlinear.o build/lensing.o build/hyrectools.o build/helium.o build/hydrogen.o build/history.o build/output.o cpp/ClassEngine.o cpp/testKlass.o -o testKlass +> c++ -O2 -fopenmp build/arrays.o build/background.o build/common.o build/dei_rkck.o build/evolver_ndf15.o build/evolver_rkck.o build/growTable.o build/helium.o build/history.o build/hydrogen.o build/hyperspherical.o build/hyrectools.o build/input.o build/lensing.o build/nonlinear.o build/output.o build/parser.o build/perturbations.o build/primordial.o build/quadrature.o build/sparse.o build/spectra.o build/thermodynamics.o build/transfer.o cpp/ClassEngine.o cpp/Engine.o cpp/testKlass.o -o testKlass then run ./testKlass.cc diff --git a/cpp/testKlass.cc b/cpp/testKlass.cc index 7f0bb7e6..0d708ee7 100644 --- a/cpp/testKlass.cc +++ b/cpp/testKlass.cc @@ -18,28 +18,26 @@ int main(int argc,char** argv){ //CLASS config ClassParams pars; - pars.add("H0",70.3); + //pars.add("H0",70.3); + pars.add("100*theta_s",1.04); pars.add("omega_b",0.0220); - //pars.add("omega_b",0.0215); pars.add("omega_cdm",0.1116); pars.add("A_s",2.42e-9); pars.add("n_s",.96); - pars.add("z_reio",10.4); + pars.add("tau_reio",0.09); - pars.add("k_pivot",0.002); + pars.add("k_pivot",0.05); pars.add("YHe",0.25); pars.add("output","tCl,pCl,lCl"); //pol +clphi pars.add("l_max_scalars",l_max_scalars); - pars.add("lensing",false); //note boolean + pars.add("lensing",true); //note boolean - pars.add("modes","s"); //scalars - pars.add("ic","ad"); //adiabatic + ClassEngine* KKK(0); try{ //le calculateur de spectres - ClassEngine* KKK(0); if (argc==2){ string pre=string(argv[1]); KKK=new ClassEngine(pars,pre); @@ -49,29 +47,12 @@ int main(int argc,char** argv){ } cout.precision( 16 ); - - for (int l=2;l<=l_max_scalars;l++) { - try{ - cout << l << "\t" - << KKK->getCl(ClassEngine::TT,l) << "\t" - << KKK->getCl(ClassEngine::TE,l) << "\t" - << KKK->getCl(ClassEngine::EE,l) << "\t" - << KKK->getCl(ClassEngine::BB,l)<< "\t" - << KKK->getCl(ClassEngine::PP,l)<< "\t" - << KKK->getCl(ClassEngine::TP,l)<< "\t" - << KKK->getCl(ClassEngine::EP,l) - << endl; - } - catch (std::exception &e){ - cout << "GIOSH" << e.what() << endl; - } - - } - delete KKK; + KKK->writeCls(cout); } - //class engine throws std:exceptions - catch(exception& e){ - cerr << e.what() << endl; + catch (std::exception &e){ + cout << "GIOSH" << e.what() << endl; } + delete KKK; + }