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

Last change on this file since 4013 was 3952, checked in by cmv, 15 years ago

ajout evolution de w, cmv 22/02/2011

File size: 9.2 KB
Line 
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
12#include "constcosmo.h"
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
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,wa"<<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
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.,wa=0.;
47 // -- ouvert matter only
48 //double h100=0.71, om0=0.3, or0=0., ol0=0.,w0=-1,wa=0..;
49 // -- plat matter only
50 //double h100=0.71, om0=1., or0=0., ol0=0.,w0=-1.,wa=0.; flat = 1;
51 // -- plat lambda only
52 //double h100=0.71, om0=0., or0=0., ol0=1.,w0=-1.,wa=0.; flat = 2;
53
54 // -- parametre d'integration
55 double perc=0.01,dzinc=-1.,dzmax=-1.;
56 unsigned short glorder=4;
57 // -- redshift
58 double z1=0., z2=-1., dz=-1.;
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,%lf",&h100,&om0,&or0,&ol0,&w0,&wa);
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.;
92 if(z2<=z1) z2 = z1+1.;
93 if(dz<=0.) dz = 10.*(z2-z1);
94 cout<<"z1="<<z1<<" z2="<<z2<<" dz="<<dz<<endl;
95 cout<<"perc="<<perc<<" dzinc="<<dzinc<<" dzmax="<<dzmax<<" glorder="<<glorder<<endl;
96 cout<<"h100="<<h100<<" om0="<<om0<<" or0="<<or0<<" ol0="<<ol0<<" w0="<<w0<<" wa="<<wa<<" flat="<<flat<<endl;
97 cout<<"todo ="<<todo<<endl;
98
99 CosmoCalc univ1(flat,true,z2);
100 univ1.SetInteg(perc,dzinc,dzmax,glorder);
101 univ1.SetDynParam(h100,om0,or0,ol0,w0,wa);
102 univ1.PrtInteg();
103 univ1.Print();
104 cout<<endl;
105
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,wa);
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;
119
120 return 0;
121}
122
123/* ----------------------------------------------------- */
124void tstprint(CosmoCalc& univ,double z1,double z2,double dz)
125{
126 if(dz>z2-z1) dz = z2-z1;
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);
131 cout<<"\nTSTPRINT(): z1="<<z1<<" z2="<<z2<<" dz="<<dz<<endl;
132 cout<<" "<<fz1<<" -> "<<fz2<<" MHz, df: "<<fz1-fz1pdz<<" , "<<fz2-fz2pdz<<" MHz"<<endl;
133 for(double z=z1;z<z2+dz/2.;z+=dz) {
134 cout<<"\n-- z = "<<z<<" ("<<1000.*Fr_HyperFin_Par/(1.+z)<<" MHz)"<<endl;
135 univ.Print(z);
136 cout<<"Volume comoving in [z,z+"<<dz<<"] for 4Pi sr: "
137 <<univ.Vol4Pi(z,z+dz)<<" Mpc^3"<<endl;
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);
146 cout<<"dLOScom/dz -> "<<dloscom<<" Mpc com"<<endl;
147 }
148
149}
150
151/* ----------------------------------------------------- */
152void tstprint(CosmoCalc& univ1,CosmoCalc& univ2,double z1,double z2,double dz)
153{
154 if(dz>z2-z1) dz = z2-z1;
155 cout<<"\nTSTPRINT(): z1="<<z1<<" z2="<<z2<<" dz="<<dz<<endl;
156 for(double z=z1;z<z2+dz/2.;z+=dz) {
157 cout<<endl<<"--spline: z = "<<z<<endl;
158 univ1.Print(z);
159 cout<<"Volume comoving in [z,z+dz] for 4Pi sr: "
160 <<univ1.Vol4Pi(z,z+dz)<<" Mpc^3"<<endl;
161 cout<<"--integ: z = "<<z<<endl;
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{
171 if(dz>z2-z1) dz = z2-z1;
172 cout<<"\nTSTSPEED(): z1="<<z1<<" z2="<<z2<<" dz="<<dz<<endl;
173 double sum = 0.;
174 int_4 n=0;
175 PrtTim("-- Beginning");
176 for(double z=z1;z<z2+dz/2.;z+=dz) {
177 sum += univ.Dang(z);
178 n++;
179 }
180 if(n>0) cout<<"n="<<n<<" ...dum="<<sum/n<<endl;
181 PrtTim("-- Ending");
182}
183
184/* ----------------------------------------------------- */
185void tstntuple(CosmoCalc& univ,double z1,double z2,double dz)
186{
187 if(dz>z2-z1) dz = z2-z1;
188 cout<<"\nTSTNTUPLE(): z1="<<z1<<" z2="<<z2<<" dz="<<dz<<endl;
189 double norm = univ.Dhubble(); // 1.
190 double norm3 = pow(norm,3.);
191 const int n = 15;
192 const char *vname[n] = {
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
218 cout<<">>>> Ecriture"<<endl;
219 nt.Info()["flat"] = univ.Flat();
220 nt.Info()["h100"] = univ.h100();
221 nt.Info()["Olambda0"] = univ.Olambda0();
222 nt.Info()["W0"] = univ.W0();
223 nt.Info()["Wa"] = univ.Wa();
224 nt.Info()["Omatter0"] = univ.Omatter0();
225 nt.Info()["Obaryon0"] = univ.Obaryon0();
226 nt.Info()["Orelat0"] = univ.Orelat0();
227 nt.Info()["Ocurv0"] = univ.Ocurv0();
228 nt.Info()["Otot0"] = univ.Otot0();
229 nt.Info()["ZMax"] = univ.ZMax();
230
231 string tag = "cmvtuniv_nt.ppf";
232 POutPersist pos(tag);
233 tag = "nt"; pos.PutObject(nt,tag);
234}
235
236
237/*
238openppf cmvtuniv_nt.ppf
239
240set cut 1
241set cut z<100.
242set cut z<10.
243
244zone
245n/plot nt.hz%z $cut ! "nsta connectpoints"
246
247zone
248n/plot nt.dl%z $cut ! "nsta connectpoints"
249n/plot nt.da%z $cut ! "nsta connectpoints same red"
250n/plot nt.dtc%z $cut ! "nsta connectpoints same blue"
251n/plot nt.dlc%z $cut ! "nsta connectpoints same green"
252
253zone 2 2
254n/plot nt.dvc%z $cut ! "nsta connectpoints"
255n/plot nt.vc0%z $cut ! "nsta connectpoints"
256n/plot nt.vcdz%z $cut ! "nsta connectpoints"
257
258zone
259n/plot nt.ot%z $cut ! "nsta connectpoints"
260n/plot nt.om%z $cut ! "nsta connectpoints same blue"
261n/plot nt.or%z $cut ! "nsta connectpoints same red"
262n/plot nt.ol%z $cut ! "nsta connectpoints same green"
263n/plot nt.ok%z $cut ! "nsta connectpoints same orange"
264
265 */
266
267/* ----------------------------------------------------- */
268void tstinterp(CosmoCalc& univ,double z1,double z2,double dz)
269{
270 if(dz>z2-z1) dz = z2-z1;
271 cout<<"\nTSTINTERP(): z1="<<z1<<" z2="<<z2<<" dz="<<dz<<endl;
272 // On remplit les donnes completes
273 vector<double> Z,D;
274 for(double z=z1;z<z2+dz/2.;z+=dz) {
275 Z.push_back(z);
276 D.push_back(univ.Dloscom(z));
277 }
278 // On remplit un sous tableau
279 int ninc = 5;
280 vector<double> Dinterp;
281 double zmin = Z[0], zmax = Z[0];
282 for(unsigned int i=0;i<Z.size();i+=ninc) {
283 Dinterp.push_back(D[i]);
284 zmax = Z[i];
285 }
286 InterpFunc interp(zmin,zmax,Dinterp);
287 unsigned short ok;
288
289 const int n = 8;
290 const char *vname[n] = {"z","d","di","dl","dp","zi","zl","zp"};
291 NTuple nt(n,vname);
292 double xnt[n];
293
294 for(unsigned int i=0;i<Z.size();i++) {
295 if(Z[i]>zmax) break;
296 xnt[0] = Z[i];
297 xnt[1] = D[i];
298 xnt[2] = interp(Z[i]);
299 xnt[3] = interp.Linear(Z[i],ok);
300 xnt[4] = interp.Parab(Z[i],ok);
301 xnt[5] = xnt[6] = xnt[7] = 0.;
302 nt.Fill(xnt);
303 }
304 cout<<">>>> Ecriture"<<endl;
305 string tag = "cmvtuniv_int.ppf";
306 POutPersist pos(tag);
307 tag = "nt"; pos.PutObject(nt,tag);
308}
309
310/*
311openppf cmvtuniv_int.ppf
312
313n/plot nt.d%z ! ! "nsta connectpoints"
314n/plot nt.di%z ! ! "nsta connectpoints same green"
315n/plot nt.dl%z ! ! "nsta connectpoints same red"
316n/plot nt.dp%z ! ! "nsta connectpoints same blue"
317
318n/plot nt.di-d%z ! ! "nsta connectpoints green"
319n/plot nt.dl-d%z ! ! "nsta connectpoints same red"
320n/plot nt.dp-d%z ! ! "nsta connectpoints same blue"
321
322n/plot nt.(di-d)/d%z d>0 ! "nsta connectpoints green"
323n/plot nt.(dl-d)/d%z d>0 ! "nsta connectpoints same red"
324n/plot nt.(dp-d)/d%z d>0 ! "nsta connectpoints same blue"
325
326*/
Note: See TracBrowser for help on using the repository browser.