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

Last change on this file since 3281 was 3248, checked in by cmv, 18 years ago

correction erreur format dans sscanf cmv 15/05/2007

File size: 6.7 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 usage(void);
16void usage(void) {cout<<"cmvtuniv z1,z2,dz [perc,dzinc,dzmax,glorder]"<<endl;}
17
18void tstprint(CosmoCalc& univ,double z1,double z2,double dz);
19void tstprint(CosmoCalc& univ1,CosmoCalc& univ2,double z1,double z2,double dz);
20void tstspeed(CosmoCalc& univ,double z1,double z2,double dz);
21void tstntuple(CosmoCalc& univ,double z1,double z2,double dz);
22void tstinterp(CosmoCalc& univ,double z1,double z2,double dz);
23
24const double deg2rad = M_PI/180.;
25
26int main(int narg,char *arg[])
27{
28 unsigned short flat = 0;
29 // -- WMAP
30 double h100=0.71, om0=0.267804, or0=7.9e-05, ol0=0.73,w0=-1.;
31 // -- ouvert matter only
32 //double h100=0.71, om0=0.3, or0=0., ol0=0.,w0=-1.;
33 // -- plat matter only
34 //double h100=0.71, om0=1., or0=0., ol0=0.,w0=-1.; flat = 1;
35 // -- plat lambda only
36 //double h100=0.71, om0=0., or0=0., ol0=1.,w0=-1.; flat = 2;
37
38 double z1=0., z2=-1., dz=-1.;
39 if(narg>1) sscanf(arg[1],"%lf,%lf,%lf",&z1,&z2,&dz);
40 if(z2<=z1) z2 = z1+1.;
41 if(dz<0.) dz = 10.*(z2-z1);
42 cout<<"z1="<<z1<<" z2="<<z2<<" dz="<<dz<<endl;
43
44 double perc=0.01,dzinc=-1.,dzmax=5.; unsigned short glorder=4;
[3248]45 if(narg>2) sscanf(arg[2],"%lf,%lf,%lf,%hu",&perc,&dzinc,&dzmax,&glorder);
[3115]46 if(dzinc<=0.) dzinc = dz/2.;
47 cout<<" perc="<<perc<<" dzinc="<<dzinc<<" dzmax="<<dzmax<<" glorder="<<glorder<<endl;
48
49 CosmoCalc univ(flat,true,z2);
50 univ.SetInteg(perc,dzinc,dzmax,glorder);
51 univ.SetDynParam(h100,om0,or0,ol0,w0);
52 univ.Print();
53
54 CosmoCalc univ1(univ);
55 univ1.SetInteg(perc,dzinc,dzmax,glorder);
56 univ1.SetDynParam(h100,om0,or0,ol0,w0);
57 univ1.Print();
58
[3193]59 tstprint(univ,z1,z2,dz);
[3115]60 //tstprint(univ,univ1,z1,z2,dz);
61 //tstspeed(univ,z1,z2,dz);
62 //tstntuple(univ,z1,z2,dz);
[3193]63 //tstinterp(univ,z1,z2,dz);
[3115]64
65 return 0;
66}
67
68/* ----------------------------------------------------- */
69void tstprint(CosmoCalc& univ,double z1,double z2,double dz)
70{
71 cout<<"\nTSTPRINT()"<<endl;
72 double dzz = dz; if(dzz>z2-z1) dzz = 0.01;
73 for(double z=z1;z<z2+dz/2.;z+=dz) {
74 cout<<"--"<<endl;
75 univ.Print(z);
76 cout<<"Volume comoving in [z,z+"<<dzz<<"] for 4Pi sr: "
77 <<univ.Vol4Pi(z,z+dzz)<<" Mpc^3"<<endl;
78 double dang = univ.Dang(z);
79 double a = deg2rad/3600.;
80 cout<<"1\" -> "<<dang*a<<" Mpc = "<<dang*a*(1.+z)<<" Mpc com"<<endl;
81 a = deg2rad/60.;
82 cout<<"1\' -> "<<dang*a<<" Mpc = "<<dang*a*(1.+z)<<" Mpc com"<<endl;
83 a = deg2rad;
84 cout<<"1d -> "<<dang*a<<" Mpc = "<<dang*a*(1.+z)<<" Mpc com"<<endl;
85 double dloscom = univ.Dhubble() / univ.E(z);
86 cout<<"dz=1 -> "<<dloscom<<" Mpc com"<<endl;
87
88 }
89}
90
91/* ----------------------------------------------------- */
92void tstprint(CosmoCalc& univ1,CosmoCalc& univ2,double z1,double z2,double dz)
93{
94 cout<<"\nTSTPRINT()"<<endl;
95 for(double z=z1;z<z2+dz/2.;z+=dz) {
96 cout<<endl<<"--spline:"<<endl;
97 univ1.Print(z);
98 cout<<"Volume comoving in [z,z+dz] for 4Pi sr: "
99 <<univ1.Vol4Pi(z,z+dz)<<" Mpc^3"<<endl;
100 cout<<"--integ:"<<endl;
101 univ2.Print(z);
102 cout<<"Volume comoving in [z,z+dz] for 4Pi sr: "
103 <<univ2.Vol4Pi(z,z+dz)<<" Mpc^3"<<endl;
104 }
105}
106
107/* ----------------------------------------------------- */
108void tstspeed(CosmoCalc& univ,double z1,double z2,double dz)
109{
110 cout<<"\nTSTSPEED()"<<endl;
111 double sum = 0.;
112 int_4 n=0;
113 for(double z=z1;z<z2+dz/2.;z+=dz) {
114 sum += univ.Dang(z);
115 n++;
116 }
117 if(n>0) cout<<"... "<<sum/n<<endl;
118}
119
120/* ----------------------------------------------------- */
121void tstntuple(CosmoCalc& univ,double z1,double z2,double dz)
122{
123 cout<<"\nTSTNTUPLE()"<<endl;
124 double norm = univ.Dhubble(); // 1.
125 double norm3 = pow(norm,3.);
126 const int n = 15;
127 char *vname[n] = {
128 "z","hz","om","or","ol","ok","ot","ob",
129 "dtc","dlc","da","dl",
130 "dvc","vc0","vcdz"
131 };
132 NTuple nt(n,vname);
133 double xnt[n];
134 for(double z=z1;z<z2+dz/2.;z+=dz) {
135 xnt[0] = z;
136 xnt[1] = univ.H(z);
137 xnt[2] = univ.Omatter(z);
138 xnt[3] = univ.Orelat(z);
139 xnt[4] = univ.Olambda(z);
140 xnt[5] = univ.Ocurv(z);
141 xnt[6] = univ.Otot(z);
142 xnt[7] = univ.Obaryon(z);
143 xnt[8] = univ.Dtrcom(z)/norm;
144 xnt[9] = univ.Dloscom(z)/norm;
145 xnt[10] = univ.Dang(z)/norm;
146 xnt[11] = univ.Dlum(z)/norm;
147 xnt[12] = univ.dVol(z)/norm3;
148 xnt[13] = univ.Vol4Pi(z)/norm3;
149 xnt[14] = univ.Vol4Pi(z,z+dz)/norm3;
150 nt.Fill(xnt);
151 }
152 cout<<">>>> Ecriture"<<endl;
153 string tag = "cmvtuniv.ppf";
154 POutPersist pos(tag);
155 tag = "nt"; pos.PutObject(nt,tag);
156}
157
158
159/*
160openppf cmvtuniv.ppf
161
162set cut 1
163set cut z<100.
164set cut z<10.
165
166zone
167n/plot nt.hz%z $cut ! "nsta connectpoints"
168
169zone
170n/plot nt.dl%z $cut ! "nsta connectpoints"
171n/plot nt.da%z $cut ! "nsta connectpoints same red"
172n/plot nt.dtc%z $cut ! "nsta connectpoints same blue"
173n/plot nt.dlc%z $cut ! "nsta connectpoints same green"
174
175zone 2 2
176n/plot nt.dvc%z $cut ! "nsta connectpoints"
177n/plot nt.vc0%z $cut ! "nsta connectpoints"
178n/plot nt.vcdz%z $cut ! "nsta connectpoints"
179
180zone
181n/plot nt.ot%z $cut ! "nsta connectpoints"
182n/plot nt.om%z $cut ! "nsta connectpoints same blue"
183n/plot nt.or%z $cut ! "nsta connectpoints same red"
184n/plot nt.ol%z $cut ! "nsta connectpoints same green"
185n/plot nt.ok%z $cut ! "nsta connectpoints same orange"
186
187 */
188
189/* ----------------------------------------------------- */
190void tstinterp(CosmoCalc& univ,double z1,double z2,double dz)
191{
192 cout<<"\nTSTINTERP()"<<endl;
193
194 // On repmplit les donnes completes
195 vector<double> Z,D;
196 for(double z=z1;z<z2+dz/2.;z+=dz) {
197 Z.push_back(z);
198 D.push_back(univ.Dloscom(z));
199 }
200 // On remplit un sous tableau
201 int ninc = 5;
202 vector<double> Dinterp;
203 double zmin = Z[0], zmax = Z[0];
204 for(int i=0;i<Z.size();i+=ninc) {
205 Dinterp.push_back(D[i]);
206 zmax = Z[i];
207 }
208 InterpFunc interp(zmin,zmax,Dinterp);
209 unsigned short ok;
210
211 const int n = 8;
212 char *vname[n] = {"z","d","di","dl","dp","zi","zl","zp"};
213 NTuple nt(n,vname);
214 double xnt[n];
215
216 for(int i=0;i<Z.size();i++) {
217 if(Z[i]>zmax) break;
218 xnt[0] = Z[i];
219 xnt[1] = D[i];
220 xnt[2] = interp(Z[i]);
221 xnt[3] = interp.Linear(Z[i],ok);
222 xnt[4] = interp.Parab(Z[i],ok);
223 xnt[5] = xnt[6] = xnt[7] = 0.;
224 nt.Fill(xnt);
225 }
226 cout<<">>>> Ecriture"<<endl;
227 string tag = "cmvtuniv.ppf";
228 POutPersist pos(tag);
229 tag = "nt"; pos.PutObject(nt,tag);
230}
231
232/*
233openppf cmvtuniv.ppf
234
235n/plot nt.d%z ! ! "nsta connectpoints"
236n/plot nt.di%z ! ! "nsta connectpoints same green"
237n/plot nt.dl%z ! ! "nsta connectpoints same red"
238n/plot nt.dp%z ! ! "nsta connectpoints same blue"
239
240n/plot nt.di-d%z ! ! "nsta connectpoints green"
241n/plot nt.dl-d%z ! ! "nsta connectpoints same red"
242n/plot nt.dp-d%z ! ! "nsta connectpoints same blue"
243
244n/plot nt.(di-d)/d%z d>0 ! "nsta connectpoints green"
245n/plot nt.(dl-d)/d%z d>0 ! "nsta connectpoints same red"
246n/plot nt.(dp-d)/d%z d>0 ! "nsta connectpoints same blue"
247
248*/
Note: See TracBrowser for help on using the repository browser.