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