1 | #include "machdefs.h"
|
---|
2 | #include <iostream>
|
---|
3 | #include <stdlib.h>
|
---|
4 | #include <stdio.h>
|
---|
5 | #include <string.h>
|
---|
6 | #include <math.h>
|
---|
7 | #include <unistd.h>
|
---|
8 |
|
---|
9 | #include "pexceptions.h"
|
---|
10 | #include "cspline.h"
|
---|
11 |
|
---|
12 | #include "constcosmo.h"
|
---|
13 | #include "cosmocalc.h"
|
---|
14 | #include "geneutils.h"
|
---|
15 |
|
---|
16 | namespace SOPHYA {
|
---|
17 |
|
---|
18 | ///////////////////////////////////////////////////////////
|
---|
19 | //*********************** CosmoCalc *********************//
|
---|
20 | ///////////////////////////////////////////////////////////
|
---|
21 |
|
---|
22 | //----------------------------------------------------------
|
---|
23 | // flat = 0 : no compute Otot from other
|
---|
24 | // = 1 : change Omatter to get Otot=1
|
---|
25 | // = 2 : change Olambda to get Otot=1
|
---|
26 | // = 3 : change Orelat to get Otot=1
|
---|
27 | // usespline = "true" : compute integrale then use spline to extrapolate
|
---|
28 | // = "false" : compute integrale everytime
|
---|
29 | // zmax : maximum redshift(only if usespline=true)
|
---|
30 |
|
---|
31 | CosmoCalc::CosmoCalc(unsigned short flat,bool usespline,double zmax)
|
---|
32 | : _flat(flat),
|
---|
33 | _zold(-1.) , _integval(0.),
|
---|
34 | _usespline(usespline), _computespl(true), _zmax(zmax), _spline(NULL),
|
---|
35 | _nspl(0), _xspl(NULL), _yspl(NULL)
|
---|
36 | {
|
---|
37 | if(_usespline && _zmax<=0.) {
|
---|
38 | cout<<"CosmoCalc::CosmoCalc: Error bad _zmax value zmax="<< _zmax<<endl;
|
---|
39 | throw ParmError("CosmoCalc::UseSpline: Error bad _zmax value");
|
---|
40 | }
|
---|
41 | DefaultParam();
|
---|
42 | SetInteg();
|
---|
43 | }
|
---|
44 |
|
---|
45 | CosmoCalc::CosmoCalc(CosmoCalc& univ)
|
---|
46 | : _spline(NULL), _xspl(NULL), _yspl(NULL)
|
---|
47 | {
|
---|
48 | Clone(univ);
|
---|
49 | if(_usespline && _zmax<=0.) {
|
---|
50 | cout<<"CosmoCalc::CosmoCalc: Error bad _zmax value zmax="<< _zmax<<endl;
|
---|
51 | throw ParmError("CosmoCalc::UseSpline: Error bad _zmax value");
|
---|
52 | }
|
---|
53 | }
|
---|
54 |
|
---|
55 | CosmoCalc::~CosmoCalc(void)
|
---|
56 | {
|
---|
57 | if(_spline != NULL) delete _spline; _spline = NULL;
|
---|
58 | if(_xspl != NULL) delete [] _xspl; _xspl = NULL;
|
---|
59 | if(_yspl != NULL) delete [] _yspl; _yspl = NULL;
|
---|
60 | }
|
---|
61 |
|
---|
62 | void CosmoCalc::Clone(CosmoCalc& univ)
|
---|
63 | {
|
---|
64 | _flat = univ._flat;
|
---|
65 | _h100 = univ._h100;
|
---|
66 | _H0 = univ._H0;
|
---|
67 | _Olambda0 = univ._Olambda0;
|
---|
68 | _W0 = univ._W0;
|
---|
69 | _Omatter0 = univ._Omatter0;
|
---|
70 | _Obaryon0 = univ._Obaryon0;
|
---|
71 | _Orelat0 = univ._Orelat0;
|
---|
72 | _Otot0 = univ._Otot0;
|
---|
73 | _Ocurv0 = univ._Ocurv0;
|
---|
74 | _Dhubble = univ._Dhubble;
|
---|
75 |
|
---|
76 | _dperc = univ._dperc;
|
---|
77 | _dzinc = univ._dzinc;
|
---|
78 | _dzmax = univ._dzmax;
|
---|
79 | _glorder = univ._glorder;
|
---|
80 | if(_xgausl.size()>0) {
|
---|
81 | _xgausl.resize(0); _wgausl.resize(0);
|
---|
82 | for(int i=0;i<(int)_xgausl.size();i++) {
|
---|
83 | _xgausl.push_back(univ._xgausl[i]);
|
---|
84 | _wgausl.push_back(univ._wgausl[i]);
|
---|
85 | }
|
---|
86 | }
|
---|
87 |
|
---|
88 | _zold = -1.;
|
---|
89 | _integval = -1.;
|
---|
90 |
|
---|
91 | _usespline = univ._usespline;
|
---|
92 | _computespl = true;
|
---|
93 | _zmax = univ._zmax;
|
---|
94 | _nspl = 0;
|
---|
95 | if(_spline) delete _spline; _spline = NULL;
|
---|
96 | if(_xspl) delete [] _xspl; _xspl = NULL;
|
---|
97 | if(_yspl) delete [] _yspl; _yspl = NULL;
|
---|
98 | }
|
---|
99 |
|
---|
100 | //----------------------------------------------------------
|
---|
101 | // On va couper l'intervalle entre [0,zmax]:
|
---|
102 | // On parcourt [0,zmax] par pas de dzinc
|
---|
103 | // et on cree un intervalle
|
---|
104 | // - si la fonction varie de plus de "dperc"
|
---|
105 | // - ou si l'increment en z est superieur a "dzmax"
|
---|
106 | void CosmoCalc::SetInteg(double dperc,double dzinc,double dzmax,unsigned short order)
|
---|
107 | {
|
---|
108 | _dperc = dperc; _dzinc = dzinc; _dzmax = dzmax;
|
---|
109 |
|
---|
110 | if(_dperc<=0.) _dperc = 0.01;
|
---|
111 |
|
---|
112 | if(_dzinc<=0.) _dzinc = _zmax/100.;
|
---|
113 | if(_dzinc>=_zmax/2.) _dzinc = _zmax/2.; // Protection against big dzinc
|
---|
114 |
|
---|
115 | if(_dzmax<=0.) _dzmax = _zmax;
|
---|
116 | if(_dzmax<_dzinc) _dzmax = _dzinc;
|
---|
117 |
|
---|
118 | _glorder = order;
|
---|
119 | if(_glorder<=1) _glorder = 4;
|
---|
120 | Compute_GaussLeg(_glorder,_xgausl,_wgausl,0.,1.);
|
---|
121 |
|
---|
122 | _computespl=true;
|
---|
123 | }
|
---|
124 |
|
---|
125 |
|
---|
126 | void CosmoCalc::PrtInteg(void)
|
---|
127 | {
|
---|
128 | printf("CosmoCalc::PrtInteg: dperc=%g dzinc=%g dzmax=%g glorder=%hu\n",_dperc,_dzinc,_dzmax,_glorder);
|
---|
129 | }
|
---|
130 |
|
---|
131 | void CosmoCalc::SetObaryon0(double v)
|
---|
132 | {
|
---|
133 | _Obaryon0 = v;
|
---|
134 | if(_Obaryon0<0.) {
|
---|
135 | cout<<"CosmoCalc::SetObaryon0: Error bad _Obaryon0 value: "<<_Obaryon0<<endl;
|
---|
136 | throw ParmError("CosmoCalc::SetObaryon0: Error bad _Obaryon0 value");
|
---|
137 | }
|
---|
138 | }
|
---|
139 |
|
---|
140 | void CosmoCalc::SetDynParam(double h100,double om0,double or0,double ol0,double w0)
|
---|
141 | {
|
---|
142 | _computespl=true;
|
---|
143 |
|
---|
144 | _h100 = h100;
|
---|
145 | _H0 = 100. * _h100 ;
|
---|
146 | _Dhubble = SpeedOfLight_Cst / _H0;
|
---|
147 |
|
---|
148 | _Omatter0 = om0;
|
---|
149 | _Orelat0 = or0;
|
---|
150 | _Olambda0 = ol0;
|
---|
151 | _W0 = w0;
|
---|
152 | _Otot0 = _Olambda0 + _Omatter0 + _Orelat0;
|
---|
153 | _Ocurv0 = 1. - _Otot0;
|
---|
154 | if( _h100<0. || _Omatter0<0. || _Orelat0<0. || _Olambda0<0. ) {
|
---|
155 | cout<<"CosmoCalc::SetDynParam: Error bad parameter value"<<endl;
|
---|
156 | throw ParmError("CosmoCalc::SetDynParam: Error bad parameter value");
|
---|
157 | }
|
---|
158 | if(_flat==0) return;
|
---|
159 |
|
---|
160 | _Otot0 = 1.; _Ocurv0 = 0.;
|
---|
161 | if(_flat==1) {
|
---|
162 | _Omatter0 = _Otot0 - _Olambda0 - _Orelat0;
|
---|
163 | if( _Omatter0<0. ) {
|
---|
164 | cout<<"CosmoCalc::SetDynParam: Error bad _Omatter0 value: "<<_Omatter0<<endl;
|
---|
165 | throw ParmError("CosmoCalc::SetDynParam: Error bad _Omatter0 value");
|
---|
166 | }
|
---|
167 | return;
|
---|
168 | }
|
---|
169 |
|
---|
170 | //--
|
---|
171 | if(_flat==2) {
|
---|
172 | _Olambda0 = _Otot0 - _Omatter0 - _Orelat0;
|
---|
173 | if( _Olambda0<0. ) {
|
---|
174 | cout<<"CosmoCalc::SetDynParam: Error bad _Olambda0 value: "<<_Olambda0<<endl;
|
---|
175 | throw ParmError("CosmoCalc::SetDynParam: Error bad _Olambda0 value");
|
---|
176 | }
|
---|
177 | return;
|
---|
178 | }
|
---|
179 |
|
---|
180 | //--
|
---|
181 | if(_flat==3) {
|
---|
182 | _Orelat0 = _Otot0 - _Omatter0 - _Olambda0;
|
---|
183 | if( _Orelat0<0. ) {
|
---|
184 | cout<<"CosmoCalc::SetDynParam: Error bad _Orelat0 value: "<<_Orelat0<<endl;
|
---|
185 | throw ParmError("CosmoCalc::SetDynParam: Error bad _Orelat0 value");
|
---|
186 | }
|
---|
187 | return;
|
---|
188 | }
|
---|
189 |
|
---|
190 | cout<<"CosmoCalc::SetDynParam: Error bad _flat value: "<<_flat<<endl;
|
---|
191 | throw ParmError("CosmoCalc::SetDynParam: Error bad _flat value");
|
---|
192 |
|
---|
193 | }
|
---|
194 |
|
---|
195 | void CosmoCalc::DefaultParam(void)
|
---|
196 | {
|
---|
197 | _computespl=true;
|
---|
198 |
|
---|
199 | double h100 = 0.71;
|
---|
200 | double ol0 = 0.73, w0 = -1.;
|
---|
201 | double om0 = 0.135/(h100*h100);
|
---|
202 | // Relat = photons (2.725 K) + neutrinos (1.9 K)
|
---|
203 | double or0 = 2.47e-5 * (1. + 21./8.*pow(T_NU_Par/T_CMB_Par,4.)) / (h100*h100);
|
---|
204 | SetDynParam(h100,om0,or0,ol0,w0);
|
---|
205 | _Obaryon0 = 0.0224/(h100*h100);
|
---|
206 |
|
---|
207 | return;
|
---|
208 | }
|
---|
209 |
|
---|
210 | //----------------------------------------------------------
|
---|
211 | void CosmoCalc::Print(double z)
|
---|
212 | {
|
---|
213 | if(z<0.) z = 0.;
|
---|
214 |
|
---|
215 | printf("CosmoCalc::Print(spl=%d,zmax=%g,flat=%u) for z=%g\n",int(_usespline),ZMax(),Flat(),z);
|
---|
216 | printf("h100=%g H0=%g Dhub=%g H(z)=%g Rhoc=%g g/cm^3 =%g Msol/Mpc^3\n"
|
---|
217 | ,h100(),H0(),Dhubble(),H(z),Rhoc(z),Rhoc(z)*GCm3toMsolMpc3_Cst);
|
---|
218 | printf("Olambda=%g W0=%g\n",Olambda(z),_W0);
|
---|
219 | printf("Omatter=%g Obaryon=%g\n",Omatter(z),Obaryon(z));
|
---|
220 | printf("Orelat=%g\n",Orelat(z));
|
---|
221 | printf("Otot=%g Ocurv=%g\n",Otot(z),Ocurv(z));
|
---|
222 | if(z <= 0.) return;
|
---|
223 | printf("Distance comoving: los=%g Mpc, transv=%g Mpc\n",Dloscom(z),Dtrcom(z));
|
---|
224 | printf("Distance: angular=%g Mpc, lum=%g Mpc\n",Dang(z),Dlum(z));
|
---|
225 | printf("Volume comoving element: %g Mpc^3/sr/dz=1\n",dVol(z));
|
---|
226 | printf("Volume comoving in [0,z] for 4Pi sr: %g Mpc^3\n",Vol4Pi(z));
|
---|
227 |
|
---|
228 | }
|
---|
229 | //----------------------------------------------------------
|
---|
230 | double CosmoCalc::Olambda(double z)
|
---|
231 | {
|
---|
232 | double v = _Olambda0;
|
---|
233 | if(_W0 != -1.) v *= pow((1.+z),3.*(1+_W0));
|
---|
234 | return v / E2(z);
|
---|
235 | }
|
---|
236 |
|
---|
237 | double CosmoCalc::Omatter(double z)
|
---|
238 | {
|
---|
239 | return _Omatter0 * (1.+z)*(1.+z)*(1.+z) /E2(z);
|
---|
240 | }
|
---|
241 |
|
---|
242 | double CosmoCalc::Obaryon(double z)
|
---|
243 | {
|
---|
244 | return _Obaryon0 * (1.+z)*(1.+z)*(1.+z) /E2(z);
|
---|
245 | }
|
---|
246 |
|
---|
247 | double CosmoCalc::Orelat(double z)
|
---|
248 | {
|
---|
249 | double z2 = (1.+z)*(1.+z);
|
---|
250 | return _Orelat0 * z2*z2 /E2(z);
|
---|
251 | }
|
---|
252 |
|
---|
253 | double CosmoCalc::Ocurv(double z)
|
---|
254 | {
|
---|
255 | return _Ocurv0 * (1.+z)*(1.+z) /E2(z);
|
---|
256 | }
|
---|
257 |
|
---|
258 | double CosmoCalc::Otot(double z)
|
---|
259 | {
|
---|
260 | return Olambda(z)+Omatter(z)+Orelat(z);
|
---|
261 | }
|
---|
262 |
|
---|
263 | double CosmoCalc::Rhoc(double z)
|
---|
264 | // Densite critique au redshift "z" en "g/cm^3"
|
---|
265 | {
|
---|
266 | double h2 = H(z) / MpctoMeters_Cst; h2 *= h2;
|
---|
267 | return 3.* h2 / (8.*M_PI*G_Newton_Cst) * 1000.;
|
---|
268 | }
|
---|
269 |
|
---|
270 | //----------------------------------------------------------
|
---|
271 | double CosmoCalc::Dloscom(double z) /* Mpc comobile */
|
---|
272 | {
|
---|
273 | return _Dhubble * NInteg(z);
|
---|
274 | }
|
---|
275 |
|
---|
276 | double CosmoCalc::Dtrcom(double z) /* Mpc comobile */
|
---|
277 | {
|
---|
278 | double v = NInteg(z); // Zero curvature
|
---|
279 |
|
---|
280 | if(_flat) return _Dhubble * v;
|
---|
281 |
|
---|
282 | if(_Ocurv0>0.) { // hyperbolique
|
---|
283 | double s = sqrt(_Ocurv0);
|
---|
284 | v = sinh(s*v)/s;
|
---|
285 | } else if(_Ocurv0<0.) { // spherique
|
---|
286 | double s = sqrt(-_Ocurv0);
|
---|
287 | v = sin(s*v)/s;
|
---|
288 | }
|
---|
289 |
|
---|
290 | return _Dhubble * v;
|
---|
291 |
|
---|
292 | }
|
---|
293 |
|
---|
294 | double CosmoCalc::Dang(double z) /* Mpc */
|
---|
295 | {
|
---|
296 | return Dtrcom(z) / (1.+z);
|
---|
297 | }
|
---|
298 |
|
---|
299 | double CosmoCalc::Dlum(double z) /* Mpc */
|
---|
300 | {
|
---|
301 | return (1.+z) * Dtrcom(z);
|
---|
302 | }
|
---|
303 |
|
---|
304 | double CosmoCalc::dVol(double z) /* Mpc^3/ sr / unite z */
|
---|
305 | {
|
---|
306 | double d = Dtrcom(z);
|
---|
307 | return _Dhubble * d*d / E(z);
|
---|
308 | }
|
---|
309 |
|
---|
310 | //----------------------------------------------------------
|
---|
311 | double CosmoCalc::Vol4Pi(double z) /* Mpc^3 pour 4Pi sr entre [0,z] */
|
---|
312 | // --- on pose x = dm/dh = (1+z)*da/dh, s = sqrt(|Ok|)
|
---|
313 | // Ok=0 : V(z)/dh^3 = (4*Pi/3) * x^3
|
---|
314 | // Ok>0 : V(z)/dh^3 = (4*Pi/(2*Ok)) * (x*sqrt(1+Ok*x^2) - 1/s * asinh(s*x))
|
---|
315 | // Ok<0 : V(z)/dh^3 = (4*Pi/(2*Ok)) * (x*sqrt(1+Ok*x^2) - 1/s * asin(s*x) )
|
---|
316 | // --- on pose y = s*x (y>0)
|
---|
317 | // Ok>0 : V(z)/dh^3 = (4*Pi/(2*Ok*s)) * (y*sqrt(1+y^2) - asinh(y))
|
---|
318 | // Ok<0 : V(z)/dh^3 = (4*Pi/(2*Ok*s)) * (y*sqrt(1-y^2) - asin(y) )
|
---|
319 | // --- a petit "z" on a pour "y -> 0+" en faisant le DL
|
---|
320 | // Ok>0 : V(z)/dh^3 = 4*Pi*y^3 / (3*Ok*s) * (1 - 3*y^2/10) + O(y^7)
|
---|
321 | // Ok<0 : V(z)/dh^3 = -4*Pi*y^3 / (3*Ok*s) * (1 + 3*y^2/10) + O(y^7)
|
---|
322 | // (remarque: Ok^(3/2) = s*Ok)
|
---|
323 | {
|
---|
324 | double v,x = Dtrcom(z)/_Dhubble;
|
---|
325 |
|
---|
326 | if(_flat) {
|
---|
327 | v = 4.*M_PI/3. * x*x*x;
|
---|
328 | } else if(_Ocurv0>0.) {
|
---|
329 | double s = sqrt(_Ocurv0), y = s*x, y2 = y*y;
|
---|
330 | if(y<1e-6) {
|
---|
331 | v = 1. - 3.*y2/10.;
|
---|
332 | v *= 4.*M_PI*y*y2 / (3.*_Ocurv0*s);
|
---|
333 | } else {
|
---|
334 | v = y*sqrt(1.+y2) - asinh(y);
|
---|
335 | v *= 4.*M_PI/(2.*_Ocurv0*s);
|
---|
336 | }
|
---|
337 | } else if (_Ocurv0<0.) {
|
---|
338 | double s = sqrt(-_Ocurv0), y = s*x, y2 = y*y;
|
---|
339 | if(y<1e-6) {
|
---|
340 | v = 1. + 3.*y2/10.;
|
---|
341 | v *= -4.*M_PI*y*y2 / (3.*_Ocurv0*s);
|
---|
342 | } else {
|
---|
343 | v = y*sqrt(1.-y2) - asin(y);
|
---|
344 | v *= 4.*M_PI/(2.*_Ocurv0*s);
|
---|
345 | }
|
---|
346 | } else {
|
---|
347 | v = 4.*M_PI/3. * x*x*x;
|
---|
348 | }
|
---|
349 |
|
---|
350 | return v * _Dhubble*_Dhubble*_Dhubble;
|
---|
351 | }
|
---|
352 |
|
---|
353 | double CosmoCalc::Vol4Pi(double z1,double z2) /* Mpc^3 pour 4Pi sr entre [z1,z2] */
|
---|
354 | {
|
---|
355 | return Vol4Pi(z2) - Vol4Pi(z1);
|
---|
356 | }
|
---|
357 |
|
---|
358 | double CosmoCalc::E2(double z) const
|
---|
359 | {
|
---|
360 | z += 1.;
|
---|
361 | double oldum = _Olambda0;
|
---|
362 |
|
---|
363 | if(oldum>0. && _W0!=-1.) oldum *= pow(z,3.*(1.+_W0));
|
---|
364 |
|
---|
365 | return oldum + z*z*(_Ocurv0 + z*(_Omatter0+z*_Orelat0));
|
---|
366 | }
|
---|
367 |
|
---|
368 | //----------------------------------------------------------
|
---|
369 | double CosmoCalc::ZFrLos(double loscom /* Mpc com */, int niter)
|
---|
370 | // Recherche du redshift correspondant a une distance comobile
|
---|
371 | // le long de la ligne de visee (radiale) egale a "loscom" Mpc
|
---|
372 | // niter = nomber of iterations for precision measurement
|
---|
373 | {
|
---|
374 | if(niter<3) niter = 6;
|
---|
375 | double dz = ZMax()/10.; if(dz<=0.) dz = 0.1;
|
---|
376 | double zmin=0., zmax=0.;
|
---|
377 | while(Dloscom(zmax)<loscom) zmax += dz;
|
---|
378 | if(zmax==0.) return 0.;
|
---|
379 | for(int i=0; i<niter; i++) {
|
---|
380 | zmin=zmax-dz; if(zmin<0.) zmin=0.;
|
---|
381 | dz /= 10.;
|
---|
382 | for(double z=zmin; z<zmax+dz; z+=dz) {
|
---|
383 | double d = Dloscom(z);
|
---|
384 | if(d<loscom) continue;
|
---|
385 | zmax = z;
|
---|
386 | //cout<<"ZFrLos: z="<<zmax<<" d="<<d<<" / "<<loscom<<endl;
|
---|
387 | break;
|
---|
388 | }
|
---|
389 | }
|
---|
390 | return zmax;
|
---|
391 | }
|
---|
392 |
|
---|
393 | //----------------------------------------------------------
|
---|
394 | double CosmoCalc::NInteg(double z)
|
---|
395 | {
|
---|
396 | if(z<0.) {
|
---|
397 | cout<<"CosmoCalc::NInteg: Error bad z value z="<<z<<endl;
|
---|
398 | throw ParmError("CosmoCalc::NInteg: Error bad z value");
|
---|
399 | }
|
---|
400 |
|
---|
401 | // On utilise le spline
|
---|
402 | if(_usespline) {
|
---|
403 | if( (!_computespl) && (z==_zold) ) return _integval;
|
---|
404 | if(z>_zmax) {_zmax = z+_dzmax; _computespl = true;}
|
---|
405 | if(_computespl) Init_Spline();
|
---|
406 | _integval = _spline->CSplineInt(z);
|
---|
407 | _zold = z;
|
---|
408 | return _integval;
|
---|
409 | }
|
---|
410 |
|
---|
411 | // On calcule l'integrale
|
---|
412 | if(z != _zold) {
|
---|
413 | _integval = IntegrateFunc(*this,0.,z,_dperc,_dzinc,_dzmax,_glorder);
|
---|
414 | _zold = z;
|
---|
415 | }
|
---|
416 | return _integval;
|
---|
417 |
|
---|
418 | }
|
---|
419 |
|
---|
420 | int_4 CosmoCalc::Init_Spline(void)
|
---|
421 | {
|
---|
422 | if(_spline!=NULL)
|
---|
423 | {delete _spline; delete [] _xspl; delete [] _yspl;}
|
---|
424 |
|
---|
425 | //-- Look for intervalles and integrate
|
---|
426 | vector<double> x,y;
|
---|
427 | x.push_back(0.); y.push_back(0.);
|
---|
428 | double zbas=0., fbas = Integrand(zbas);
|
---|
429 | for(double z=_dzinc;;z+=_dzinc) {
|
---|
430 | double f = Integrand(z);
|
---|
431 | //cout<<fbas<<","<<f<<" : "<<fabs(f-fbas)<<" >? "<<_dperc*fabs(fbas)<<endl;
|
---|
432 | if( z>_zmax || z-zbas>_dzmax || fabs(f-fbas)>_dperc*fabs(fbas) ) {
|
---|
433 | double sum=0., dz=z-zbas;
|
---|
434 | for(unsigned short i=0;i<_glorder;i++) sum += _wgausl[i]*Integrand(zbas+_xgausl[i]*dz);
|
---|
435 | x.push_back(z); y.push_back(sum*dz);
|
---|
436 | //cout<<"...set... "<<zbas<<","<<z<<" , "<<fbas<<","<<f<<endl;
|
---|
437 | zbas = z; fbas = f;
|
---|
438 | if( z>_zmax ) break;
|
---|
439 | }
|
---|
440 | }
|
---|
441 |
|
---|
442 | //-- Protection car il faut au moins 4 points pour un spline cubique
|
---|
443 | if(x.size()<4) {
|
---|
444 | x.resize(0); y.resize(0);
|
---|
445 | x.push_back(0.); y.push_back(0.);
|
---|
446 | for(int i=1;i<4;i++) {
|
---|
447 | x.push_back(i*_zmax/3.);
|
---|
448 | double sum=0., dz=x[i]-x[i-1];
|
---|
449 | for(unsigned short i=0;i<_glorder;i++) sum += _wgausl[i]*Integrand(x[i-1]+_xgausl[i]*dz);
|
---|
450 | y.push_back(sum*dz);
|
---|
451 | }
|
---|
452 | }
|
---|
453 |
|
---|
454 | //-- Fill spline
|
---|
455 | _nspl = x.size();
|
---|
456 | _xspl = new double[_nspl];
|
---|
457 | _yspl = new double[_nspl];
|
---|
458 | for(int i=0;i<_nspl;i++) {
|
---|
459 | _xspl[i] = x[i];
|
---|
460 | _yspl[i] = y[i];
|
---|
461 | if(i!=0) _yspl[i] += _yspl[i-1];
|
---|
462 | }
|
---|
463 |
|
---|
464 | #if 1
|
---|
465 | cout<<"CosmoCalc::Init_Spline called: (zmax="<<_zmax<<") _nspl="<<_nspl<<endl;
|
---|
466 | int n = (_nspl>5)? 5: _nspl;
|
---|
467 | cout<<_nspl<<"...";
|
---|
468 | for(int i=0;i<n;i++) cout<<_xspl[i]<<" ("<<_yspl[i]<<") ";
|
---|
469 | cout<<"\n... ";
|
---|
470 | n = (_nspl<5)? 0: _nspl-5;
|
---|
471 | for(int i=n;i<_nspl;i++) cout<<_xspl[i]<<" ("<<_yspl[i]<<") ";
|
---|
472 | cout<<endl;
|
---|
473 | #endif
|
---|
474 |
|
---|
475 | double yp1 = Integrand(_xspl[0]);
|
---|
476 | double ypn = Integrand(_xspl[_nspl-1]);
|
---|
477 | _spline = new CSpline(_nspl,_xspl,_yspl,yp1,ypn,CSpline::NoNatural,false);
|
---|
478 | _spline->ComputeCSpline();
|
---|
479 | _computespl = false;
|
---|
480 |
|
---|
481 | return _nspl;
|
---|
482 | }
|
---|
483 |
|
---|
484 | //==========================================================================
|
---|
485 | //==========================================================================
|
---|
486 | //==========================================================================
|
---|
487 | double LargeurDoppler(double v, double nu)
|
---|
488 | // largeur doppler pour une vitesse v en km/s et une frequence nu
|
---|
489 | {
|
---|
490 | return v / SpeedOfLight_Cst * nu;
|
---|
491 | }
|
---|
492 |
|
---|
493 | double DzFrV(double v, double zred)
|
---|
494 | // largeur en redshift pour une vitesse v en km/s au redshift zred
|
---|
495 | {
|
---|
496 | return v / SpeedOfLight_Cst * (1. + zred);
|
---|
497 | }
|
---|
498 |
|
---|
499 | double DNuFrDz(double dzred,double nu_at_0,double zred)
|
---|
500 | // Largeur DNu pour une largeur en redshift "dzred" au redshift "zred"
|
---|
501 | // pour la frequence "nu_at_0" a z=0
|
---|
502 | // nu = NuHi(z=0)/(1.+z0)
|
---|
503 | // dnu = NuHi(z=0)/(1.+z0-dz/2) - NuHi/(1.+z0+dz/2)
|
---|
504 | // = NuHi(z=0)*dz/[ (1+z0)^2 - (dz/2)^2 ]
|
---|
505 | // = NuHi(z=0)*dz/(1.+z0)^2 / [ 1 - [dz/(1+z0)/2)]^2 ]
|
---|
506 | // = NuHi(z=0)*dz/(1.+z0)^2 / [1 - dz/(1+z0)/2] / [1 + dz/(1+z0)/2]
|
---|
507 | // ~= NuHi(z=0)*dz/(1.+z0)^2 (approx. pour dz<<z0 a l'ordre (dz/z0)^2)
|
---|
508 | {
|
---|
509 | double zp1 = 1.+zred;
|
---|
510 | return nu_at_0*dzred/(zp1*zp1)/(1.-dzred/zp1/2.)/(1.+dzred/zp1/2.);
|
---|
511 | }
|
---|
512 |
|
---|
513 | double DzFrDNu(double dnu_at_0,double nu_at_0,double zred)
|
---|
514 | // Largeur en redshift au redshift "zred" pour une largeur
|
---|
515 | // en frequence "dnu_at_0" a la frequence "nu_at_0" a z=0
|
---|
516 | {
|
---|
517 | if(dnu_at_0<=0.) return 0.;
|
---|
518 | double zp1 = 1.+zred;
|
---|
519 | double dnusnu0 = dnu_at_0/nu_at_0;
|
---|
520 | return 2./dnusnu0 * (sqrt(1.+(dnusnu0*zp1)*(dnusnu0*zp1)) - 1.);
|
---|
521 | }
|
---|
522 | double DzFrDNuApprox(double dnu_at_0,double nu_at_0,double zred)
|
---|
523 | // idem DzFrDNu mais on utilise l'approximation: dnu=NuHi(z=0)*dz/(1.+z0)^2
|
---|
524 | {
|
---|
525 | double zp1 = 1.+zred;
|
---|
526 | return dnu_at_0/nu_at_0 *(zp1*zp1);
|
---|
527 | }
|
---|
528 |
|
---|
529 | } // Fin namespace SOPHYA
|
---|