source: Sophya/trunk/Cosmo/SimLSS/cmvtuniv.cc@ 3821

Last change on this file since 3821 was 3790, checked in by cmv, 15 years ago

etude des cubes generes par le GSM, cmv 28/06/2010

File size: 8.8 KB
RevLine 
[3115]1#include "sopnamsp.h"
2#include "machdefs.h"
3#include <iostream>
4#include <stdlib.h>
5#include <stdio.h>
6#include <string.h>
7#include <math.h>
8#include <unistd.h>
9#include "timing.h"
10#include "ntuple.h"
11
[3790]12#include "constcosmo.h"
[3115]13#include "cosmocalc.h"
14#include "geneutils.h"
15
16void tstprint(CosmoCalc& univ,double z1,double z2,double dz);
17void tstprint(CosmoCalc& univ1,CosmoCalc& univ2,double z1,double z2,double dz);
18void tstspeed(CosmoCalc& univ,double z1,double z2,double dz);
19void tstntuple(CosmoCalc& univ,double z1,double z2,double dz);
20void tstinterp(CosmoCalc& univ,double z1,double z2,double dz);
21
22const double deg2rad = M_PI/180.;
23
[3313]24void usage(void);
25void usage(void) {
26 cout
27 <<"cmvtuniv [options] z1,z2"<<endl
28 <<" -D dz"<<endl
29 <<" -U h100,om0,or0,ol0,w0"<<endl
30 <<" -F flat(0,1,2)"<<endl
31 <<" -I perc,dzinc,dzmax,glorder"<<endl
32 <<" --- What has to be done:"<<endl
33 <<" -W 1/2/3/4/5"<<endl
34 <<" 1 : print info from z1 to z2 by step dz"<<endl
35 <<" 2 : compare with/without spline from z1 to z2 by step dz"<<endl
36 <<" 3 : test speed from z1 to z2 by step dz"<<endl
37 <<" 4 : fill ntuple with infos from z1 to z2 by step dz"<<endl
38 <<" 5 : test interpolation loscom from z1 to z2 by step dz"<<endl
39 <<endl;
40}
41
[3115]42int main(int narg,char *arg[])
43{
44 unsigned short flat = 0;
45 // -- WMAP
46 double h100=0.71, om0=0.267804, or0=7.9e-05, ol0=0.73,w0=-1.;
47 // -- ouvert matter only
48 //double h100=0.71, om0=0.3, or0=0., ol0=0.,w0=-1.;
49 // -- plat matter only
50 //double h100=0.71, om0=1., or0=0., ol0=0.,w0=-1.; flat = 1;
51 // -- plat lambda only
52 //double h100=0.71, om0=0., or0=0., ol0=1.,w0=-1.; flat = 2;
53
[3313]54 // -- parametre d'integration
55 double perc=0.01,dzinc=-1.,dzmax=-1.;
56 unsigned short glorder=4;
57 // -- redshift
[3115]58 double z1=0., z2=-1., dz=-1.;
[3313]59 // -- Work to be done
60 int todo = 1;
61
62 InitTim();
63
64 // Read arguments
65 char c;
66 while ((c = getopt(narg, arg, "hD:U:F:I:W:")) != -1) {
67 switch (c) {
68 case 'D' :
69 sscanf(optarg,"%lf",&dz);
70 break;
71 case 'U' :
72 sscanf(optarg,"%lf,%lf,%lf,%lf,%lf",&h100,&om0,&or0,&ol0,&w0);
73 break;
74 case 'F' :
75 sscanf(optarg,"%hu",&flat);
76 break;
77 case 'I' :
78 sscanf(optarg,"%lf,%lf,%lf,%hu",&perc,&dzinc,&dzmax,&glorder);
79 break;
80 case 'W' :
81 sscanf(optarg,"%d",&todo);
82 break;
83 case 'h' :
84 default:
85 usage();
86 return -1;
87 }
88}
89 if(optind<narg) sscanf(arg[optind],"%lf,%lf",&z1,&z2);
90
91 if(z1<0.) z1 = 0.;
[3115]92 if(z2<=z1) z2 = z1+1.;
[3313]93 if(dz<=0.) dz = 10.*(z2-z1);
[3115]94 cout<<"z1="<<z1<<" z2="<<z2<<" dz="<<dz<<endl;
[3313]95 cout<<"perc="<<perc<<" dzinc="<<dzinc<<" dzmax="<<dzmax<<" glorder="<<glorder<<endl;
96 cout<<"h100="<<h100<<" om0="<<om0<<" or0="<<or0<<" ol0="<<ol0<<" w0="<<w0<<" flat="<<flat<<endl;
97 cout<<"todo ="<<todo<<endl;
[3115]98
[3313]99 CosmoCalc univ1(flat,true,z2);
[3115]100 univ1.SetInteg(perc,dzinc,dzmax,glorder);
101 univ1.SetDynParam(h100,om0,or0,ol0,w0);
[3285]102 univ1.PrtInteg();
[3115]103 univ1.Print();
[3313]104 cout<<endl;
[3115]105
[3313]106 if(todo==1) tstprint(univ1,z1,z2,dz);
107 else if(todo==2) {
108 CosmoCalc univ2(flat,false,z2);
109 univ2.SetInteg(perc,dzinc,dzmax,glorder);
110 univ2.SetDynParam(h100,om0,or0,ol0,w0);
111 univ2.PrtInteg();
112 univ2.Print();
113 tstprint(univ1,univ2,z1,z2,dz);
114 }
115 else if(todo==3) tstspeed(univ1,z1,z2,dz);
116 else if(todo==4) tstntuple(univ1,z1,z2,dz);
117 else if(todo==5)tstinterp(univ1,z1,z2,dz);
118 else cout<<"Unknown job to be done !!!!! todo="<<todo<<endl;
[3115]119
120 return 0;
121}
122
123/* ----------------------------------------------------- */
124void tstprint(CosmoCalc& univ,double z1,double z2,double dz)
125{
[3313]126 if(dz>z2-z1) dz = z2-z1;
[3790]127 double fz1 = 1000.*Fr_HyperFin_Par/(1.+z1);
128 double fz1pdz = 1000.*Fr_HyperFin_Par/(1.+z1+dz);
129 double fz2 = 1000.*Fr_HyperFin_Par/(1.+z2);
130 double fz2pdz = 1000.*Fr_HyperFin_Par/(1.+z2+dz);
[3313]131 cout<<"\nTSTPRINT(): z1="<<z1<<" z2="<<z2<<" dz="<<dz<<endl;
[3790]132 cout<<" "<<fz1<<" -> "<<fz2<<" MHz, df: "<<fz1-fz1pdz<<" , "<<fz2-fz2pdz<<" MHz"<<endl;
[3115]133 for(double z=z1;z<z2+dz/2.;z+=dz) {
[3790]134 cout<<"\n-- z = "<<z<<" ("<<1000.*Fr_HyperFin_Par/(1.+z)<<" MHz)"<<endl;
[3115]135 univ.Print(z);
[3313]136 cout<<"Volume comoving in [z,z+"<<dz<<"] for 4Pi sr: "
137 <<univ.Vol4Pi(z,z+dz)<<" Mpc^3"<<endl;
[3115]138 double dang = univ.Dang(z);
139 double a = deg2rad/3600.;
140 cout<<"1\" -> "<<dang*a<<" Mpc = "<<dang*a*(1.+z)<<" Mpc com"<<endl;
141 a = deg2rad/60.;
142 cout<<"1\' -> "<<dang*a<<" Mpc = "<<dang*a*(1.+z)<<" Mpc com"<<endl;
143 a = deg2rad;
144 cout<<"1d -> "<<dang*a<<" Mpc = "<<dang*a*(1.+z)<<" Mpc com"<<endl;
145 double dloscom = univ.Dhubble() / univ.E(z);
[3790]146 cout<<"dLOScom/dz -> "<<dloscom<<" Mpc com"<<endl;
[3313]147 }
[3115]148
149}
150
151/* ----------------------------------------------------- */
152void tstprint(CosmoCalc& univ1,CosmoCalc& univ2,double z1,double z2,double dz)
153{
[3313]154 if(dz>z2-z1) dz = z2-z1;
155 cout<<"\nTSTPRINT(): z1="<<z1<<" z2="<<z2<<" dz="<<dz<<endl;
[3115]156 for(double z=z1;z<z2+dz/2.;z+=dz) {
[3313]157 cout<<endl<<"--spline: z = "<<z<<endl;
[3115]158 univ1.Print(z);
159 cout<<"Volume comoving in [z,z+dz] for 4Pi sr: "
160 <<univ1.Vol4Pi(z,z+dz)<<" Mpc^3"<<endl;
[3313]161 cout<<"--integ: z = "<<z<<endl;
[3115]162 univ2.Print(z);
163 cout<<"Volume comoving in [z,z+dz] for 4Pi sr: "
164 <<univ2.Vol4Pi(z,z+dz)<<" Mpc^3"<<endl;
165 }
166}
167
168/* ----------------------------------------------------- */
169void tstspeed(CosmoCalc& univ,double z1,double z2,double dz)
170{
[3313]171 if(dz>z2-z1) dz = z2-z1;
172 cout<<"\nTSTSPEED(): z1="<<z1<<" z2="<<z2<<" dz="<<dz<<endl;
[3115]173 double sum = 0.;
174 int_4 n=0;
[3313]175 PrtTim("-- Beginning");
[3115]176 for(double z=z1;z<z2+dz/2.;z+=dz) {
177 sum += univ.Dang(z);
178 n++;
179 }
[3313]180 if(n>0) cout<<"n="<<n<<" ...dum="<<sum/n<<endl;
181 PrtTim("-- Ending");
[3115]182}
183
184/* ----------------------------------------------------- */
185void tstntuple(CosmoCalc& univ,double z1,double z2,double dz)
186{
[3313]187 if(dz>z2-z1) dz = z2-z1;
188 cout<<"\nTSTNTUPLE(): z1="<<z1<<" z2="<<z2<<" dz="<<dz<<endl;
[3115]189 double norm = univ.Dhubble(); // 1.
190 double norm3 = pow(norm,3.);
191 const int n = 15;
[3572]192 const char *vname[n] = {
[3115]193 "z","hz","om","or","ol","ok","ot","ob",
194 "dtc","dlc","da","dl",
195 "dvc","vc0","vcdz"
196 };
197 NTuple nt(n,vname);
198 double xnt[n];
199 for(double z=z1;z<z2+dz/2.;z+=dz) {
200 xnt[0] = z;
201 xnt[1] = univ.H(z);
202 xnt[2] = univ.Omatter(z);
203 xnt[3] = univ.Orelat(z);
204 xnt[4] = univ.Olambda(z);
205 xnt[5] = univ.Ocurv(z);
206 xnt[6] = univ.Otot(z);
207 xnt[7] = univ.Obaryon(z);
208 xnt[8] = univ.Dtrcom(z)/norm;
209 xnt[9] = univ.Dloscom(z)/norm;
210 xnt[10] = univ.Dang(z)/norm;
211 xnt[11] = univ.Dlum(z)/norm;
212 xnt[12] = univ.dVol(z)/norm3;
213 xnt[13] = univ.Vol4Pi(z)/norm3;
214 xnt[14] = univ.Vol4Pi(z,z+dz)/norm3;
215 nt.Fill(xnt);
216 }
217 cout<<">>>> Ecriture"<<endl;
[3313]218 string tag = "cmvtuniv_nt.ppf";
[3115]219 POutPersist pos(tag);
220 tag = "nt"; pos.PutObject(nt,tag);
221}
222
223
224/*
[3313]225openppf cmvtuniv_nt.ppf
[3115]226
227set cut 1
228set cut z<100.
229set cut z<10.
230
231zone
232n/plot nt.hz%z $cut ! "nsta connectpoints"
233
234zone
235n/plot nt.dl%z $cut ! "nsta connectpoints"
236n/plot nt.da%z $cut ! "nsta connectpoints same red"
237n/plot nt.dtc%z $cut ! "nsta connectpoints same blue"
238n/plot nt.dlc%z $cut ! "nsta connectpoints same green"
239
240zone 2 2
241n/plot nt.dvc%z $cut ! "nsta connectpoints"
242n/plot nt.vc0%z $cut ! "nsta connectpoints"
243n/plot nt.vcdz%z $cut ! "nsta connectpoints"
244
245zone
246n/plot nt.ot%z $cut ! "nsta connectpoints"
247n/plot nt.om%z $cut ! "nsta connectpoints same blue"
248n/plot nt.or%z $cut ! "nsta connectpoints same red"
249n/plot nt.ol%z $cut ! "nsta connectpoints same green"
250n/plot nt.ok%z $cut ! "nsta connectpoints same orange"
251
252 */
253
254/* ----------------------------------------------------- */
255void tstinterp(CosmoCalc& univ,double z1,double z2,double dz)
256{
[3313]257 if(dz>z2-z1) dz = z2-z1;
258 cout<<"\nTSTINTERP(): z1="<<z1<<" z2="<<z2<<" dz="<<dz<<endl;
259 // On remplit les donnes completes
[3115]260 vector<double> Z,D;
261 for(double z=z1;z<z2+dz/2.;z+=dz) {
262 Z.push_back(z);
263 D.push_back(univ.Dloscom(z));
264 }
265 // On remplit un sous tableau
266 int ninc = 5;
267 vector<double> Dinterp;
268 double zmin = Z[0], zmax = Z[0];
[3285]269 for(unsigned int i=0;i<Z.size();i+=ninc) {
[3115]270 Dinterp.push_back(D[i]);
271 zmax = Z[i];
272 }
273 InterpFunc interp(zmin,zmax,Dinterp);
274 unsigned short ok;
275
276 const int n = 8;
[3572]277 const char *vname[n] = {"z","d","di","dl","dp","zi","zl","zp"};
[3115]278 NTuple nt(n,vname);
279 double xnt[n];
280
[3285]281 for(unsigned int i=0;i<Z.size();i++) {
[3115]282 if(Z[i]>zmax) break;
283 xnt[0] = Z[i];
284 xnt[1] = D[i];
285 xnt[2] = interp(Z[i]);
286 xnt[3] = interp.Linear(Z[i],ok);
287 xnt[4] = interp.Parab(Z[i],ok);
288 xnt[5] = xnt[6] = xnt[7] = 0.;
289 nt.Fill(xnt);
290 }
291 cout<<">>>> Ecriture"<<endl;
[3313]292 string tag = "cmvtuniv_int.ppf";
[3115]293 POutPersist pos(tag);
294 tag = "nt"; pos.PutObject(nt,tag);
295}
296
297/*
[3313]298openppf cmvtuniv_int.ppf
[3115]299
300n/plot nt.d%z ! ! "nsta connectpoints"
301n/plot nt.di%z ! ! "nsta connectpoints same green"
302n/plot nt.dl%z ! ! "nsta connectpoints same red"
303n/plot nt.dp%z ! ! "nsta connectpoints same blue"
304
305n/plot nt.di-d%z ! ! "nsta connectpoints green"
306n/plot nt.dl-d%z ! ! "nsta connectpoints same red"
307n/plot nt.dp-d%z ! ! "nsta connectpoints same blue"
308
309n/plot nt.(di-d)/d%z d>0 ! "nsta connectpoints green"
310n/plot nt.(dl-d)/d%z d>0 ! "nsta connectpoints same red"
311n/plot nt.(dp-d)/d%z d>0 ! "nsta connectpoints same blue"
312
313*/
Note: See TracBrowser for help on using the repository browser.