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

Last change on this file since 3784 was 3572, checked in by cmv, 17 years ago

char* -> const char* pour regler les problemes de deprecated string const... + comparaison unsigned signed + suppression EVOL_PLANCK rz+cmv 07/02/2009

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