-
Notifications
You must be signed in to change notification settings - Fork 0
/
cosmo.cpp
1543 lines (1282 loc) · 39.2 KB
/
cosmo.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/** ******************************************
cosmo.cpp calculates some useful comological parameters
*******************************************
*******************************************/
#include <math.h>
#include <nrD.h>
#include <nr.h>
#include <nrutil.h>
#include <utilities.h>
#include <cosmo.h>
#include <algorithm>
#include <limits>
#include <stdexcept>
#include <assert.h>
//#include <gsl/gsl_integration_glfixed_table_alloc.h>
#ifdef ENABLE_GSL
#include <gsl/gsl_errno.h>
#include <gsl/gsl_integration.h>
#include <gsl/gsl_sf.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_spline.h>
#include <gsl/gsl_rng.h>
#endif
#include "utilities.h"
#define JMAX 34
#define JMAXP (JMAX+1)
#define K 6
#define NRANSI
#define Hubble_length 3.0e3 /* Mpc/h */
int kmax,kount;
double *xp,**yp,dxsav;
static double alph_static; /* DR-distance parameter */
static double Omo_static, Oml_static;
std::string to_string(const CosmoParamSet &p){
switch (p) {
case CosmoParamSet::WMAP5yr :
return "WMAP5yr";
break;
case CosmoParamSet::Millennium :
return "Millennium";
break;
case CosmoParamSet::Planck1yr :
return "Planck1yr";
break;
case CosmoParamSet::Planck15 :
return "Planck15";
break;
case CosmoParamSet::Planck18 :
return "Planck18";
break;
case CosmoParamSet::BigMultiDark :
return "BigMultiDark";
break;
case CosmoParamSet::Uchuu :
return "Uchuu";
break;
default:
return "NoSet";
break;
}
}
std::ostream &operator<<(std::ostream &os,const CosmoParamSet &p){
return os << to_string(p);
}
using namespace std;
COSMOLOGY::COSMOLOGY(double omegam,double omegal,double hubble, double w, double wa,bool justdistances) :
cosmo_set(CosmoParamSet::none),init_structure_functions(false), h(hubble), Omo(omegam), Oml(omegal), ww(w) , ww1(wa){
n=1.0;
Omnu=0;
Nnu=3.0;
dndlnk=0.0;
gamma=0.55;
sig8 = 0.812;
Omb = 0.02225/h/h;
darkenergy=1;
/* if 2 gamma parameterization is used for dark energy */
/* if 1 w,w_1 parameterization is used for dark energy */
if(!justdistances){
setinternals();
}else{
// interpolate functions
z_interp = 10.0;
n_interp = 1024;
calc_interp_dist();
}
}
COSMOLOGY::COSMOLOGY(const COSMOLOGY &cosmo){
h = cosmo.h;
Omo = cosmo.Omo;
Oml = cosmo.Oml;
ww = cosmo.ww;
n = cosmo.n;
Omnu = cosmo.Omnu;
Nnu = cosmo.Nnu;
dndlnk = cosmo.dndlnk;
gamma = cosmo.gamma;
ww1 = cosmo.ww1;
sig8 = cosmo.sig8;
Omb = 0.02225/h/h;
darkenergy = cosmo.darkenergy;
init_structure_functions = cosmo.init_structure_functions;
cosmo_set = cosmo.cosmo_set;
setinternals();
}
COSMOLOGY::COSMOLOGY(CosmoParamSet cosmo_p):init_structure_functions(false)
{
SetConcordenceCosmology(cosmo_p);
setinternals();
cosmo_set = cosmo_p;
}
COSMOLOGY::~COSMOLOGY(){
}
COSMOLOGY& COSMOLOGY::operator=(const COSMOLOGY &cosmo){
if(this == &cosmo) return *this;
h = cosmo.h;
Omo = cosmo.Omo;
Oml = cosmo.Oml;
ww = cosmo.ww;
n = cosmo.n;
Omnu = cosmo.Omnu;
Nnu = cosmo.Nnu;
dndlnk = cosmo.dndlnk;
gamma = cosmo.gamma;
ww1 = cosmo.ww1;
Omb = 0.02225/h/h;
sig8 = cosmo.sig8;
darkenergy = cosmo.darkenergy;
init_structure_functions = cosmo.init_structure_functions;
cosmo_set = cosmo.cosmo_set;
setinternals();
return *this;
}
void COSMOLOGY::setinternals(){
init_structure_functions = true;
TFmdm_set_cosm();
power_normalize(sig8);
// allocate step and weight for gauleg integration
ni = 64;
xf.resize(ni);
wf.resize(ni);
gauleg(0.,1.,&xf[0]-1,&wf[0]-1,ni);
// construct table of log(1+z), time, and \delta_c for interpolation
Utilities::fill_linear(vlz,ni,0.,1.7);
double dc;
for(int i=0;i<ni;i++){
double z = -1. + pow(10.,vlz[i]);
double Omz=Omegam(z);
if(Omo<1 && Oml==0) dc=1.68647*pow(Omz,0.0185);
if(Omo+Oml==1) dc=1.68647*pow(Omz,0.0055);
vDeltaCz.push_back(dc/Dgrowth(z));
vt.push_back(time(z));
}
// interpolate functions
z_interp = 10.0;
n_interp = 1024;
calc_interp_dist();
}
/**
* \brief Sets cosmology to WMAP 2009 model. This is done automatically in the constructor.
*/
void COSMOLOGY::SetConcordenceCosmology(CosmoParamSet cosmo_p){
cosmo_set = cosmo_p;
if(cosmo_p == CosmoParamSet::WMAP5yr){
// set cosmological parameters to standard WMAP 5r values
// Komatsu et al. 2009, ApJ 180, 330
// does not set power spectrum normalization
// which needs to be done separately
Omo=0.1358;
Omb=0.02267;
h=0.705;
Omo/=h*h;
Omb/=h*h;
Oml=1.0-Omo;
ww=-1.0;
ww1=0.0;
n=1.0;
Omnu=0;
Nnu=3.0;
dndlnk=0.0;
gamma=0.55;
sig8=0.812;
darkenergy=1;
}else if(cosmo_p == CosmoParamSet::Planck1yr){
Oml = 0.6817;
Omo = 1-Oml;
h = 0.6704;
Omb = 0.022032/h/h;
ww=-1.0;
ww1=0.0;
n=1.0;
Omnu=0;
Nnu=3.0;
dndlnk=0.0;
gamma=0.55;
sig8 = 0.829;
darkenergy=1;
/* if 2 gamma parameterization is used for dark energy */
/* if 1 w,w_1 parameterization is used for dark energy */
}else if(cosmo_p == CosmoParamSet::Planck15){
// Final Planck cosmology Ade et al. 2015
Omo = 0.308;
Oml = 1-Omo;
h = 0.678;
Omb = 0.02225/h/h;
ww=-1.0;
ww1=0.0;
n=0.968;
Omnu=0;
Nnu=3.0;
dndlnk=0.0;
gamma=0.55;
sig8 = 0.8347;
darkenergy=1;
}else if(cosmo_p == CosmoParamSet::Uchuu){
// Final Planck cosmology Ade et al. 2015
Omo = 0.3089;
Oml = 1-Omo;
h = 0.6774;
Omb = 0.02230/h/h;
ww=-1.0;
ww1=0.0;
n=0.9667;
Omnu=0;
Nnu=3.0;
dndlnk=0.0;
gamma=0.55;
sig8 = 0.8159;
darkenergy=1;
}else if(cosmo_p == CosmoParamSet::Planck18){
// Final Planck cosmology Aghanim, 2018
h = 0.674;
Omo = 0.315;
Oml = 1-Omo;
Omb = 0.0224/h/h;
ww=-1.0;
ww1=0.0;
n=0.965;
Omnu=0;
Nnu=3.0;
dndlnk=0.0;
gamma=0.55;
sig8 = 0.811;
darkenergy=1;
}else if(cosmo_p == CosmoParamSet::Millennium){
// The cosmology used in the Millennium simulations
Omo=0.25;
Omb=0.02267;
h=0.73;
Omb/=h*h;
Oml=1.0-Omo;
ww=-1.0;
ww1=0.0;
n=1.0;
Omnu=0.0;
Nnu=3.0;
dndlnk=0.0;
gamma=0.55;
sig8 = 0.9;
darkenergy=1;
}else if (cosmo_p == CosmoParamSet::BigMultiDark){
Oml = 0.692885;
Omo = 1-Oml;
h = 0.677700;
Omb = 0.022032/h/h;
ww=-1.0;
ww1=0.0;
n=1.0;
Omnu=0;
Nnu=3.0;
dndlnk=0.0;
gamma=0.55;
sig8 = 0.829;
darkenergy=1;
}
}
/**
* \brief Print cosmological parameters
*/
void COSMOLOGY::PrintCosmology(short physical) const {
cout << "parameters set :" << cosmo_set << "\n";
cout << "h: " << h << "\n";
cout << "n: " << n << "\n";
cout << "dndlnk: " << dndlnk << "\n";
cout << "A: " << A << "\n";
cout << "sig8: " << sig8 << "\n";
if(physical==0){
cout << "Omo: " << Omo << "\n";
cout << "Oml: " << Oml << "\n";
cout << "Omb: " << Omb << "\n";
cout << "Omnu: " << Omnu << "\n";
cout << "Nnu: " << Nnu << "\n";
}
if(physical==1){
cout << "Omo hh: " << Omo*h*h << "\n";
cout << "Oml hh: " << Oml*h*h << "\n";
cout << "Omb hh: " << Omb*h*h << "\n";
cout << "Omnu hh: " << Omnu*h*h << "\n";
cout << "Nnu: " << Nnu << "\n";
}
if(darkenergy==2) cout << "darkenery=" << darkenergy << " gamma=" << gamma << "\n";
else cout << "darkenery: "<< darkenergy << " w: " << ww << " w1: " << ww1 << "\n";
}
/**
* \brief Print cosmological parameters
*/
std::string COSMOLOGY::print(short physical) const {
std::string out;
out = "h: " + std::to_string(h) + " ";
out += " n: " + std::to_string(n) + " ";
out += " dndlnk: " + std::to_string(dndlnk) + " ";
out += " A: " + std::to_string(A) + " ";
out += " sig8: " + std::to_string(sig8) + " ";
if(physical==0){
out += " Omo: " + std::to_string(Omo) + " ";
out += " Oml: " + std::to_string(Oml) + " ";
out += " Omb: " + std::to_string(Omb) + " ";
out += " Omnu: " + std::to_string(Omnu) + " ";
out += " Nnu: " + std::to_string(Nnu) + " ";
}
if(physical==1){
out += " Omo hh: " + std::to_string(Omo*h*h) + " ";
out += " Oml hh: " + std::to_string(Oml*h*h) + " ";
out += " Omb hh: " + std::to_string(Omb*h*h) + " ";
out += " Omnu hh: " + std::to_string(Omnu*h*h) + " ";
out += " Nnu: " + std::to_string(Nnu) + " ";
}
if(darkenergy==2) out += " darkenery=" + std::to_string(darkenergy) + " gamma="
+ std::to_string(gamma) + " ";
else out += " darkenery: "+ std::to_string(darkenergy) + " w: " + std::to_string(ww)
+ " w1: " + std::to_string(ww1) + " ";
return out;
}
/**
* \brief see if cosmologies are identical
*/
int cosmo_compare(COSMOLOGY *cos1, COSMOLOGY *cos2){
return 1-(cos1->gethubble() == cos2->gethubble())*(cos1->getindex() == cos2->getindex())
*(cos1->getSigma8() == cos2->getSigma8())
*(cos1->getOmega_matter() == cos2->getOmega_matter())*(cos1->getOmega_lambda() == cos2->getOmega_lambda())
*(cos1->getOmega_baryon() == cos2->getOmega_baryon())*(cos1->getOmega_neutrino() == cos2->getOmega_neutrino())
*(cos1->getW() == cos2->getW())*(cos1->getW1() == cos2->getW1())
*(cos1->getNneutrino() == cos2->getNneutrino());
}
/**
* \brief Copy a cosmology
*/
void cosmo_copy(CosmoHndl cos1, CosmoHndl cos2){
//cos1->physical=cos2->physical;
cos1->setOmega_matter(cos2->getOmega_matter());
cos1->setOmega_lambda(cos2->getOmega_lambda());
cos1->setOmega_baryon(cos2->getOmega_baryon());
cos1->setOmega_neutrino(cos2->getOmega_neutrino());
cos1->setNneutrino(cos2->getNneutrino());
cos1->sethubble(cos2->gethubble());
cos1->setW(cos2->getW());
cos1->setW1(cos2->getW1());
cos1->setindex(cos2->getindex());
cos1->setdndlnk(cos2->getdndlnk());
cos1->setgamma(cos2->getgamma());
cos1->setDEtype(cos2->getDEtype());
cos1->power_normalize(cos2->getSigma8());
}
/**
* \brief Curvature radius in Mpc
*/
double COSMOLOGY::rcurve() const{
if(Omo+Oml != 1.0){
return Hubble_length/(h*sqrt(fabs(1-Omo-Oml))); /** curvature scale **/
}
return 0;
}
double COSMOLOGY::DpropDz(double z){
double a=1.0/(1.0+z);
return a*drdz(1/a);
}
/**
* \brief Matter density parameter at redshift z
*/
double COSMOLOGY::Omegam(double z) const{
return Omo*pow(1+z,3)/( Omo*pow(1+z,3)+(1-Omo-Oml)*pow(1+z,2)+Oml );
}
/**
* \brief Comoving Dyer-Roeder angular size distance for lambda=0
*/
double COSMOLOGY::DRradius(double zo,double z,double pfrac){
double zl,Omr,Omz,Da[2],Ho;
int nok,nbad;
Omo_static=Omo;
Oml_static=Oml;
Ho=h/Hubble_length;
alph_static=1.5*(1-pfrac);
/* if(Oml_static !=0.0){
printf("ERROR in DRradius: Oml_static != 0\n");
return 0.0;
}*/
zl=1+z;
if(zo==0 && (Oml==0 && alph_static==0)){
if(Omo==1.0){
return 2*( zl*zl-pow(zl,-0.5) )/(zl*5*Ho);
}else if(Oml==0){
Omr=sqrt(1-Omo);
Omz=sqrt(1+Omo*(zl-1));
return zl*( (2-5*Omo) + Omz*( Omo*(3*zl+2)-2 )/(zl*zl) + 1.5*Omo*Omo*log( (1+Omr)*(Omz-Omr)/( (1-Omr)*(Omz+Omr) ) )/Omr)/(Ho*4*pow(1-Omo,2));/**/
}
}else{
if((z-zo)<0.001) return (z-zo)/(Ho*(1+zo)*(1+zo)*sqrt(1+Omo*zo+Oml*(pow(1+zo,-2)-1)) );
Da[0]=0.0;
Da[1]=-(1+zo)/(zl*zl*sqrt(1+Omo*z+Oml*(pow(zl,-2)-1)));
odeintD(Da-1,2,z,zo,1.0e-6,(z-zo)*0.1,0,&nok,&nbad,ders,bsstepD);
/*return (1+z)*Da[0]/Ho;*/
return Da[0]/Ho;
}
return 0;
}
/**
* \brief Comoving Dyer-Roeder angular size distance for lambda=0 and pfrac = 1 (all matter in particles)
*/
double COSMOLOGY::DRradius2(double zo,double z){
double zl,Omr,Omz,Da[2],ds,dl,Ho;
int nok,nbad;
Omo_static=Omo;
Oml_static=Oml;
Ho=h/Hubble_length;
/* if(Oml !=0.0){
printf("ERROR in DRradius: Oml != 0\n");
return 0.0;
}*/
alph_static=0;
zl=1+z;
if(Omo==1.0){
ds=2*( zl*zl-pow(zl,-0.5) )/(zl*5*Ho);
if(zo==0.0){ return ds;
}else{
zl=zo+1;
dl=2*( zl*zl-pow(zl,-0.5) )/(zl*5*Ho);
return ds-dl*(1+z)/(1+zo);
/*return ds*(1+zo)-dl*(1+z);*/
}
/* return 2*( zl*zl-pow(zl,-0.5) )/(zl*5*Ho); */
}else if(Oml==0){
Omr=sqrt(1-Omo);
Omz=sqrt(1+Omo*(zl-1));
ds= zl*( (2-5*Omo) + Omz*( Omo*(3*zl+2)-2 )/(zl*zl) + 1.5*Omo*Omo*log( (1+Omr)*(Omz-Omr)/( (1-Omr)*(Omz+Omr) ) )/Omr)/(Ho*4*pow(1-Omo,2));/**/
if(zo==0.0){ return ds;
}else{
zl=zo+1;
dl=zl*( (2-5*Omo) + Omz*( Omo*(3*zl+2)-2 )/(zl*zl) + 1.5*Omo*Omo*log( (1+Omr)*(Omz-Omr)/( (1-Omr)*(Omz+Omr) ) )/Omr)/(Ho*4*pow(1-Omo,2));/**/
return ds-dl*(1+z)/(1+zo);
/* return ds*(1+zo)-dl*(1+z); */
/*return (1+zo)*( ds-dl );*/
}
/* return zl*( (2-5*Omo) + Omz*( Omo*(3*zl+2)-2 )/(zl*zl) + 1.5*Omo*Omo*log( (1+Omr)*(Omz-Omr)/( (1-Omr)*(Omz+Omr) ) )/Omr)/(Ho*4*pow(1-Omo,2));*/
}else{
if((z-zo)<0.001) return (z-zo)/(Ho*(1+zo)*(1+zo)*sqrt(1+Omo*zo+Oml*(pow(1+zo,-2)-1)) );
Da[0]=0.0;
Da[1]=-1./(zl*zl*sqrt(1+Omo*z+Oml*(pow(zl,-2)-1)));
odeintD(Da-1,2,z,zo,1.0e-6,(z-zo)*0.1,0,&nok,&nbad,ders,bsstepD);
/*return (1+z)*Da[0]/Ho;*/
return Da[0]/Ho;
}
}
void ders(double z,double Da[],double dDdz[]){
dDdz[1]=Da[2];
dDdz[2]=-3*Da[2]/(1+z) - (0.5*(Omo_static-2*Oml_static*pow(1+z,-3))*Da[2]+alph_static*Omo_static*Da[1]/(1+z) )/(1+z*Omo_static+(pow(1+z,-2)-1)*Oml_static);
}
/**
* \brief Linear growth factor normalized to 1 at z=0
*/
double COSMOLOGY::Dgrowth(double z) const{
double a,Omot,Omlt,g,go;
assert(init_structure_functions);
a=1./(1+z);
if(Omo==1 && Oml==0){
return a;
}else{
go=2.5*Omo/( pow(Omo,4.0/7.0)-Oml+(1+0.5*Omo)*(1+Oml/70) );
Omot=Omo/(Omo+Oml*a*a*a-a*(Omo+Oml-1));
Omlt=a*a*a*Oml*Omot/Omo;
g=2.5*Omot/( pow(Omot,4.0/7.0)-Omlt+(1+0.5*Omot)*(1+Omlt/70) );
return a*g/go;
}
}
/**
* \brief comoving critical density in M_sun/Mpc^3
*/
double COSMOLOGY::rho_crit_comoving(double z) const {
return CRITD2*h*h*( Omo*pow(1+z,3)+Oml-(Omo+Oml-1)*pow(1+z,2) )/pow(1+z,3);
}
/**
* \brief The derivative of the comoving radial distance with respect to redshift in units of Ho^-1, x=1+z
*/
double drdz_wrapper(double x, void *params){
return static_cast<CosmoHndl>(params)->COSMOLOGY::drdz(x);
}
double COSMOLOGY::drdz(double x) const{
double temp;
temp=Omo*x*x*x+Oml-(Omo+Oml-1)*x*x;
if(temp<=0.0) return -1.0e30; // non-physical values
return 1.0/sqrt(temp);
}
/**
* \brief Same as drdz, but incorporates dark energy through ww and ww1.
*/
double drdz_dark_wrapper(double x, void *params){
return static_cast<CosmoHndl>(params)->COSMOLOGY::drdz_dark(x);
}
double COSMOLOGY::drdz_dark(double x) const{
return 1.0 / sqrt(Omo*x*x*x+Oml*dark_factor(x)-(Omo+Oml-1)*x*x);
}
inline double COSMOLOGY::dark_factor(double x) const{
if(ww == -1 && ww1 == 0) return 1;
return pow(x,3*(1+ww+ww1))*exp(-3*ww1*(x-1)/x);
}
double COSMOLOGY::ddrdzdOmo(double x) const{
double E=drdz_dark(x);
return -0.5*(x*x*x-dark_factor(x))*E*E*E;
}
double COSMOLOGY::ddrdzdw(double x) const{
double E=drdz_dark(x);
return -0.5*3*Oml*log(x)*dark_factor(x)*E*E*E;
}
double COSMOLOGY::ddrdzdw1(double x) const{
double E=drdz_dark(x);
return -0.5*3*Oml*(log(x) - (x-1)/x)*dark_factor(x)*E*E*E;
}
double COSMOLOGY::coorDist(double zo,double z) const{
assert(zo >= 0);
assert(z >= 0);
// interpolation
if(zo < z_interp && z < z_interp)
return interp(coorDist_interp, z) - interp(coorDist_interp, zo);
if(zo > z) return 0;
if( (ww ==-1.0) && (ww1 == 0.0) ) return Utilities::nintegrateF(drdz_struct(*this),1+zo,1+z,1.0e-9)*Hubble_length/h;
return Utilities::nintegrateF(drdzdark_struct(*this),1+zo,1+z,1.0e-9)*Hubble_length/h;
//if( (ww ==-1.0) && (ww1 == 0.0) ) return nintegrateDcos(&COSMOLOGY::drdz,1+zo,1+z,1.0e-9)*Hubble_length/h;
//return nintegrateDcos(&COSMOLOGY::drdz_dark,1+zo,1+z,1.0e-9)*Hubble_length/h;
}
double COSMOLOGY::d_coorDist_dOmo(double zo,double z) const{
return Utilities::nintegrateF(ddrdzdOmo_struct(*this),1+zo,1+z,1.0e-9)*Hubble_length/h;
//return nintegrateDcos(&COSMOLOGY::ddrdzdOmo,1+zo,1+z,1.0e-9)*Hubble_length/h;
}
double COSMOLOGY::d_coorDist_dw(double zo,double z) const{
return Utilities::nintegrateF(ddrdzdw_struct(*this),1+zo,1+z,1.0e-9)*Hubble_length/h;
//return nintegrateDcos(&COSMOLOGY::ddrdzdw,1+zo,1+z,1.0e-9)*Hubble_length/h;
}
double COSMOLOGY::d_coorDist_dw1(double zo,double z) const{
return Utilities::nintegrateF(ddrdzdw1_struct(*this),1+zo,1+z,1.0e-9)*Hubble_length/h;
//return nintegrateDcos(&COSMOLOGY::ddrdzdw1,1+zo,1+z,1.0e-9)*Hubble_length/h;
}
double COSMOLOGY::radDist(double zo,double z) const {
if(zo < z_interp && z < z_interp)
return interp(radDist_interp, z) - interp(radDist_interp, zo);
if( (ww ==-1.0) && (ww1 == 0.0) ) return Utilities::nintegrateF(adrdz_struct(*this),1+zo,1+z,1.0e-9)*Hubble_length/h;
return Utilities::nintegrateF(adrdzdark_struct(*this),1+zo,1+z,1.0e-9)*Hubble_length/h;
// if( (ww ==-1.0) && (ww1 == 0.0) ) return nintegrateDcos(&COSMOLOGY::adrdz,1+zo,1+z,1.0e-9)*Hubble_length/h;
// return nintegrateDcos(&COSMOLOGY::adrdz_dark,1+zo,1+z,1.0e-9)*Hubble_length/h;
}
/**
* \brief The angular size distance in units Mpc
*
* Converts angles to proper distance NOT comoving distance.
*/
double COSMOLOGY::angDist(double zo,double z) const{
double Rcur;
if(Omo+Oml==1) return coorDist(zo,z)/(1+z);
/** curviture scale **/
Rcur=Hubble_length/(h*sqrt(fabs(1-Omo-Oml)));
if((Omo+Oml)<1.0) return Rcur*sinh(coorDist(zo,z)/Rcur)/(1+z);
return Rcur*sin(coorDist(zo,z)/Rcur)/(1+z);
}
/**
* \brief The bolometric luminosity distance in units Mpc
*/
double COSMOLOGY::lumDist(double zo,double z) const{
return pow(1+z,2)*angDist(zo,z);
}
/**
* \brief The inverse of the coordinate distance in units Mpc, returning redshift. It works within interpolation range.
*/
double COSMOLOGY::invCoorDist(double d) const
{
return invert(coorDist_interp, d);
}
/**
* \brief The inverse of the angular size distance in units Mpc, works within interpolation range.
*/
double COSMOLOGY::invComovingDist(double d) const
{
if(Omo+Oml==1) return invCoorDist(d);
double Rcurve = rcurve();
if((Omo+Oml)<1.0) return invert(coorDist_interp, Rcurve*asinh(d/Rcurve) );
return invert(coorDist_interp,Rcurve*asin(d/Rcurve) );
}
/**
* \brief The inverse of the coordinate distance in units Mpc, works within interpolation range.
*/
/**
* \brief The inverse of the radial distance in units Mpc, returning redshift. It works within interpolation range.
*/
double COSMOLOGY::invRadDist(double d) const
{
return invert(radDist_interp, d);
}
/**
* \brief Incorporates curvature for angular size distance.
*/
double COSMOLOGY::gradius(
double R /// the curvature radius
,double rd /// the coordinate
) const{
if( fabs(Omo+Oml-1) < 1.0e-4) return rd;
if((Omo+Oml)<1.0) return R*sinh(rd/R);
return R*sin(rd/R);
}
/**
* \brief Press-Schechter halo mass function - default \f$ \frac{1}{\overline{\rho}_{comoving}}\frac{dN}{d\ln M} \f$ i.e. fraction of mass or
* if caseunit==1 the \f$ \frac{dN}{dlogM} \f$
*/
double COSMOLOGY::psdfdm(
double z /// redshift
,double m /// mass
,int caseunit /// if equal to 1 return the comoving number density per unit mass
){
if(!init_structure_functions) setinternals();
double dc,Omz,sig,Dg;
Dg=Dgrowth(z);
sig=sig8*Deltao(m);
Omz=Omegam(z);
dc=1.68647;
if(Omo<1 && Oml==0) dc*=pow(Omz,0.0185);
if(Omo+Oml==1) dc*=pow(Omz,0.0055);
/*printf("dc=%e dsigdM=%e sig=%e m=%e D=%e\n",dc,dsigdM(m),sig,m,Dg);*/
double nu = pow(dc/Dg/sig,2);
switch (caseunit){
case 1:
return -Omo*rho_crit_comoving(0)*(sig8*dsigdM(m))/sig*(sqrt(2/M_PI)*sqrt(nu)*exp(-0.5*nu))/m;
break;
default:
return -(sig8*dsigdM(m))/sig*(sqrt(2/M_PI)*sqrt(nu)*exp(-0.5*nu));
}
}
/**
* \brief Sheth-Tormen mass function
*/
double COSMOLOGY::stdfdm(
double z /// redshift
,double m /// mass
,int caseunit /// if equal to 1 return the number density per unit mass TODO: Carlo, why aren't the other options explained?
){
if(!init_structure_functions) setinternals();
double dc,Omz,sig,Dg;
Dg=Dgrowth(z);
sig=sig8*Deltao(m);
Omz=Omegam(z);
dc=1.68647;
if(Omo<1 && Oml==0) dc*=pow(Omz,0.0185);
if(Omo+Oml==1) dc*=pow(Omz,0.0055);
/*return psdfdm(sig8,z,m)*( 1+0.9009*pow(Dg*sig/dc,-0.6) )
*exp(0.1465*pow(dc/(Dg*sig),2) );*/
double aST = 0.707;
double pST = 0.3;
double AST = 0.322;
double nu = aST*pow(dc/Dg/sig,2);
switch (caseunit){
case 1:
return -Omo*rho_crit_comoving(0)*(sig8*dsigdM(m))/sig*(AST*(1+1/pow(nu,pST))*sqrt(nu/M_PI/2)*exp(-0.5*nu))/m;
break;
case 2:
nu = m*sqrt(aST);
return AST*(1.+1./pow(nu,pST))*sqrt(nu/2.)*exp(-0.5*nu)/sqrt(M_PI);
break;
default:
return -(sig8*dsigdM(m))/sig*(AST*(1+1/pow(nu,pST))*sqrt(nu/2)*exp(-0.5*nu));
}
}
/**
* \brief Power-law mass function
*/
double COSMOLOGY::powerlawdfdm(
double z /// redshift
,double m /// mass
,double alpha /// slope (almost 1/6 for LCDM and cluster-size haloes)
,int caseunit /// if equal to 1 return the number density per unit mass
){
if(!init_structure_functions) setinternals();
double mstar = nonlinMass(z);
double mr = m/mstar;
double alpha0 = 1./3.;
switch (caseunit){
case 1:
return Omo*rho_crit_comoving(0)*0.6*alpha0/2.*sqrt(2/M_PI)*pow(mr,alpha)*exp(-0.5*pow(mr*pow((1+z),3./2.),alpha0*1.3))/m/m;
break;
default:
return 0.6*alpha0/2.*sqrt(2/M_PI)*pow(mr,alpha)*exp(-0.5*pow(mr*pow((1+z),3./2.),alpha0*1.3))/m/m;
}
}
/**
* \brief The cumulative comoving number density of haloes with mass larger than m
* (in solar masses) at redshift z; if the dummy argument a is given, the mass function
* times m^a is integrated. If a is omitted, a default of zero is assumed. The dummy
* argument type specifies which type of mass function is to be used, 0 PS, 1 ST or 2 power-law
* (in this case also the slope alpha can be set as an additional parameter)
*/
double COSMOLOGY::haloNumberDensity(
double m /// minimum mass of halos in Msun
, double z /// redshift
, double a /// moment of mass function that is wanted
, int type /// mass function type: 0 Press-Schecter, 1 Sheth-Torman, 2 power-law
,double alpha /// exponent of power law if type==2
){
if(!init_structure_functions) setinternals();
double n=0.0;
double lm1 = log(m);
double lm2 = 2.3*100.; // upper limit in natural log: I think 10^100 M_sun/h should be enough
double lx,x,y,y1;
for (int i=0;i<ni;i++){
lx=(lm2-lm1)*xf[i]+lm1;
x = exp(lx);
switch (type){
case 1: // Sheth-Tormen
y1=log(stdfdm(z,x,1));
break;
case 2: // power-law mass function
y1=log(powerlawdfdm(z,x,alpha,1));
break;
default: // Press-Schechter
y1=log(psdfdm(z,x,1));
break;
}
y = exp(y1+(a+1.0)*lx);
n+=wf[i]*y;
}
return n*(lm2-lm1);
}
/**
* \brief The halo total surface mass density in haloes with mass larger than m_min (solar masses)
* in the redshift bin [z1,z2] and projected to redhisft z
* in solar mass / proper Mpc^2
*
*/
double COSMOLOGY::totalMassDensityinHalos(
int type /// choice of mass function, 0 Press-Shechter, 1 Sheth-Tormen, 2 Power-law
,double alpha /// slope of power law mass function if type==2
,double m_min /// minimum halo mass in Msun
,double z
,double z1
,double z2
){
double n = 0.0;
double x,d,v,c;
for (int i=0;i<ni;i++){
x=(z2-z1)*xf[i]+z1;
d=coorDist(0.0,x);
v=4.0*PI*d*d*drdz(1+x)*Hubble_length/h;
c=haloNumberDensity(m_min,x,1.0,type,alpha);
n+=wf[i]*v*c;
}
return n*(z2-z1)/(4*PI*pow(angDist(0,z),2));
/*
tmp_type = type;
tmp_alpha = alpha;
tmp_mass = m_min;
tmp_a = 1.0;
return nintegrateDcos(&COSMOLOGY::dNdz,z1,z2,1.0e-3)/(4*PI*pow(angDist(0,z),2));
*/
}
/**
* \brief Number of halos with mass larger than m (in solar masses)
* between redshifts z1 and z2 per square degree.
*/
double COSMOLOGY::haloNumberDensityOnSky (
double mass /// minimum mass
,double z1 /// lower redshift limit
,double z2 /// higher redshift limit
,int type /// The flag type specifies which type of mass function is to be used, 0 PS or 1 ST
,double alpha /// slope of power law mass function if type==2
){
if(!init_structure_functions) setinternals();
double n = 0.0;
double x,d,v,c;
for (int i=0;i<ni;i++){
x=(z2-z1)*xf[i]+z1;
d=coorDist(0.0,x);
v=4.0*PI*d*d*drdz(1+x)*Hubble_length/h;
c=haloNumberDensity(mass,x,0.0,type,alpha);
n+=wf[i]*v*c;
}
return n*(z2-z1)/41253.;
/*
tmp_type = type;
tmp_alpha = alpha;
tmp_mass = mass;
tmp_a = 0.0;
std::cout << "totalMassDensityOnSky error = " << (ans-nintegrateDcos(&COSMOLOGY::dNdz,z1,z2,1.0e-3)/41253.)/ans << std::endl;
return ans;
return nintegrateDcos(&COSMOLOGY::dNdz,z1,z2,1.0e-3)/41253.;
*/
}
/**
* \brief The number of halos in a buffered cone between redshift z1 and z2.
*
* A buffered cone is a cone with an extra perpendicular fixed physical distance added (area(z) = pi*(\theta D + buffer*(1+z))^2).
* This geometry is useful for reducing edge effects which can be particularly bad a low redshift for small cones.
*/
double COSMOLOGY::haloNumberInBufferedCone (
double mass /// minimum mass in Msun
,double z1 /// lower redshift limit
,double z2 /// higher redshift limit
,double fov /// field of view of cone in steradians
,double buffer /// buffer length in physical Mpc (not comoving)
,int type /// The flag type specifies which type of mass function is to be used, 0 PS or 1 ST