Commit 07468a61 authored by Plaszczynski Stephane's avatar Plaszczynski Stephane
Browse files

better class tests

parent 4b2c3500
......@@ -11,12 +11,14 @@
using namespace std;
#define PLANCK_CHECKS
// example run: one can specify as a second argument a preicison file
int main(int argc,char** argv){
//jusqu'a ou en l
const int l_max_scalars=2500;
announce(argv[0]);
//macro to add try-catch blocks if macro (PLANCK_CHECKS) defined
PLANCK_DIAGNOSIS_BEGIN
//CLASS config
ClassParams pars;
......@@ -44,10 +46,12 @@ int main(int argc,char** argv){
pars.add("k_pivot",0.05);
pars.add("sBBN file",Parser::CheckPath("bbn/sBBN.dat"));
//pars.add("l_max_scalars",l_max_scalars);
//for cmb:
//pars.add("l_max_scalars",100);
//pars.add("lensing",true); //note boolean
//pars.add("output","tCl,pCl,lCl,mPk"); //pol +clphi-> mPk added for sigma8
//for structures
pars.add("output","mPk"); //pol +clphi-> mPk added for sigma8
//need to compute P(k,z) for sigma8(z)
......@@ -55,71 +59,62 @@ int main(int argc,char** argv){
pars.add("z_max_pk",1);
try{
//the class calculator (engine)
ClassEngine* engine(0);
//if a precision file is given use it (otherwise use CLASS default)
if (argc==2){
string pre=string(argv[1]);
engine=new ClassEngine(pars,pre);
}
else{
engine=new ClassEngine(pars);
}
cout << "*****************************************" << endl;
//test keyword access
const char* derived_par[]={ "H0","H(0)","z_reio","tau_reio","z_drag","rs_drag","sigma8","Dv(0.57)","Da(0.57)","H(0.57)","sigma8(0.57)", "f(0.57)","growthD(0.57)"};
const int Nder=sizeof(derived_par)/sizeof(char*);
for (size_t i=0;i<Nder;i++) cout << derived_par[i] << "\t" << engine->get(derived_par[i]) << endl;
//background structure
//valeurs de z?
const double zi[]={0,0.5,1.};
const size_t Nz=sizeof(zi)/sizeof(double);
//the class calculator (engine)
ClassEngine* engine(0);
//if a precision file is given use it (otherwise use CLASS default)
if (argc==2){
string pre=string(argv[1]);
engine=new ClassEngine(pars,pre);
}
else{
engine=new ClassEngine(pars);
}
cout << "----Engine creating with parameters: " << endl;
//engine->printFC();
cout << "----Printing some keyword values: " << endl;
struct background& ba=engine->ba;
//test keyword access
const char* derived_par[]={ "H0","H(0)","z_reio","tau_reio","z_drag","rs_drag","sigma8","Dv(0.57)","Da(0.57)","H(0.57)","sigma8(0.57)", "f(0.57)","growthD(0.57)"};
const int Nder=sizeof(derived_par)/sizeof(char*);
for (size_t i=0;i<Nder;i++)
cout << derived_par[i] << "\t" << engine->get(derived_par[i]) << endl;
//print filled strcuture
/*
for (int index_tau=0; index_tau<ba.bt_size; index_tau++) {
fprintf(stdout,
"tau=%e z=%e a=%e H=%e\n",
ba.tau_table[index_tau],
ba.z_table[index_tau],
ba.background_table[index_tau*ba.bg_size+ba.index_bg_a],
ba.background_table[index_tau*ba.bg_size+ba.index_bg_H]);
}
*/
cout << "size bt=" << ba.bt_size << endl;
//interp
for (size_t i=0;i<Nz;i++){
cout << "z=" << zi[i] << " D=" << engine->get_growthD(zi[i]) <<endl;
}
//background structure
//valeurs de z?
const double zi[]={0,0.5,1.};
const size_t Nz=sizeof(zi)/sizeof(double);
//interp
for (size_t i=0;i<Nz;i++){
cout << "z=" << zi[i] << " growthD=" << engine->get_growthD(zi[i]) <<endl;
}
//test pk
struct spectra& sp=engine->sp;
cout << "ln_tau_size=" << sp.ln_tau_size << endl;
cout << "----Testing Pk output: " << endl;
//test pk
double kval[]={1e-4,3e-4,1e-3,2e-3,1e-2,3e-2,0.1};
const vector<double> kvec(kval,kval+sizeof(kval)/sizeof(double));
vector<double> pkvec(kvec.size());
double kval[]={1e-4,3e-4,1e-3,2e-3,1e-2,3e-2,0.1};
const vector<double> kvec(kval,kval+sizeof(kval)/sizeof(double));
vector<double> pkvec(kvec.size());
engine->get_Pkvec(kvec,0.,pkvec);
for (size_t i=0;i<kvec.size();i++)
cout << "k=" << kvec[i] << "\t p(k)=" << pkvec[i] << endl;
//clean
//spectra_fast_pk_at_kvec(&ba,&sp,const_cast<double*>(&kvec[0]),kvec.size(),&pkvec[0]);
cout << "----Testing update: " << endl;
const int i_ns=pars.findIndex("n_s");
cout <<" n_s index=" << i_ns <<endl;
pars.updateVal(i_ns,"1");
engine->updateParValues(pars);
engine->get_Pkvec(kvec,0.,pkvec);
for (size_t i=0;i<kvec.size();i++) cout << "k=" << kvec[i] << "\t p(k)=" << pkvec[i] << endl;
//clean
delete engine;
for (size_t i=0;i<Nder;i++)
cout << derived_par[i] << "\t" << engine->get(derived_par[i]) << endl;
}
//class engine throws std:exceptions
catch(exception& e){
cerr << e.what() << endl;
}
delete engine;
PLANCK_DIAGNOSIS_END
}
......@@ -238,7 +238,7 @@ void announce (const string &name)
cout << endl;
IO_backend_status();
cout << endl;
CVS_status();
//CVS_status();
cout << endl;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment