-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyy_power.cpp
1183 lines (924 loc) · 33.8 KB
/
yy_power.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
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <fstream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include "cosmo.h"
#include "cluster.h"
#include "gas_model.h"
#include "xray.h"
#include "allvars.h"
#include "nrutil.h"
#include "proto.h"
#include "cfortran.h"
#define BOOST_PYTHON_MAX_ARITY 20
#define MAXBINS 500
double tarray[ntmax]; //keV
double zarray[nmmax]; //Solar unit
double rarray[nrmax];
double lambda_table[ntmax][nrmax];
double tres, zres, eres;
const double sigma_T = 0.665245854e-24; //(cm)^2 Thomson cross-section
const double m_elect = 5.10998902e2; //keV/c^2
const double megapc = 3.0856*1e18*1e6;
const double X = 0.76;// primordial hydrogen fraction
const double factor = (2.0*X+2.0)/(5.0*X+3.0);//conversion factor from gas pressure to electron pressure
using namespace std;
#define Nx 100
static double xp[Nx], yp[Nx], yp2[Nx];
static int Nspline;
std::vector<double> calc_Shaw_xray_emissivity_profile(cosmo cosm_model, float z, float Mvir, std::vector<float> x);
struct Shaw_param{
double alpha0; // fiducial : 0.18
double n_nt; // fiducial : 0.80
double beta; // fiducial : 0.50
double eps_f; // fiducial : 3.97e-6
double eps_DM; // fiducial : 0.00
double f_star; // fiducial : 0.026
double S_star; // fiducial : 0.12
double A_C; // fiducial : 1.00
};
static struct Shaw_param S;
std::vector<double> calc_Flender_xray_emissivity_profile(cosmo cosm_model, float z, float Mvir, std::vector<float> x);
std::vector<double> calc_Flender_pressure_profile(cosmo cosm_model, float z, float Mvir, std::vector<float> x);
struct Flender_param{
double alpha0; // fiducial : 0.18
double n_nt; // fiducial : 0.80
double beta; // fiducial : 0.50
double eps_f; // fiducial : 3.97e-6
double eps_DM; // fiducial : 0.00
double f_star; // fiducial : 0.026
double S_star; // fiducial : 0.12
double A_C; // fiducial : 1.00
double gamma_mod0; // fiducial : 0.10
double gamma_mod_zslope; // fiducial : 1.72
double x_break; // fiducial : 0.195
double x_smooth; // fiducial : 0.01
double n_nt_mod; // fiducial : 0.80
double clump0;
double clump_zslope;
double x_clump;
double alpha_clump1;
double alpha_clump2;
};
static struct Flender_param F;
double calc_Flender_Ysz (cosmo cosm_model, float z, float Mvir, std::vector<float> x);
void free_FFTdata();
void FFT_density_profile(double *output, double *bin, int nbin);
extern "C"
{
void fhti_(int * n, double * mu, double * q, double * dlnr,
double * kr, int * kropt, double * wsave, int * ok);
void fht_(int * n, double * a , int * dir, double * wsave);
void fhtq_(int * n, double * a , int * dir, double * wsave);
}
//FFTlog paramaters
static double logrmin;
static double logrmax;
static int N;
static double q;
static double kr;
static int kropt;
//kropt = 0 to use input kr as is;
// 1 to change kr to nearest low-ringing kr, quietly;
// 2 to change kr to nearest low-ringing kr, verbosely;
// 3 for option to change kr interactively.
static int dir;
static double *r, *a, *k, *wsave;
void set_FFTlog_param(){
logrmin=log10(1e-8);
logrmax=log10(1e+8);
N=512;
//N=64;
kr=1.;
kropt=1;
dir=1;
r= new double [N];
a= new double [N];
k= new double [N];
wsave = new double [5*N];
}
//integral with input tables
double tab_spline_and_integral(int Nbin, double *xlist, double *ylist, double *zlist);
static double R500_here;
#include "boost/python/numpy.hpp"
#include "boost/python.hpp"
#include <stdexcept>
#include <algorithm>
namespace py = boost::python;
namespace npy = boost::python::numpy;
struct cosmo_params{
double H0;
double Omega_M;
double Omega_b;
double wt;
double Omega_k;
double ns;
};
static struct cosmo_params CP;
void init_cosmology(double H0, double Omega_M, double Omega_b, double wt, double Omega_k, double ns, double nH, char *inputPk){
set_cosmology_halo_info(inputPk, Omega_M, Omega_b, wt, H0/100.0, ns);
CP.H0 = H0;
CP.Omega_M = Omega_M;
CP.Omega_b = Omega_b;
CP.wt = wt;
CP.Omega_k = Omega_k;
CP.ns = CP.ns;
//set_lambda_table(tarray,rarray,lambda_table,nH,1);
}
void free_cosmology(){
free_halo_info();
}
void set_Flender_params(double p0, double p1, double p2, double p3, double p4, double p5, double p6, double p7, double p8, double p9, double p10, double p11, double p12, double p13, double p14, double p15, double p16, double p17) {
F.alpha0 =p0;
F.n_nt =p1;
F.beta =p2;
F.eps_f =p3;
F.eps_DM =p4;
F.f_star =p5;
F.S_star =p6;
F.A_C =p7;
F.gamma_mod0 =p8;
F.gamma_mod_zslope =p9;
F.x_break =p10;
F.x_smooth =p11;
F.n_nt_mod =p12;
F.clump0 =p13;
F.clump_zslope =p14;
F.x_clump =p15;
F.alpha_clump1 =p16;
F.alpha_clump2 =p17;
}
npy::ndarray return_yy_power(npy::ndarray x_input){
int nzbin = 11;
float zmin = 1e-3;
float zmax = 3.0;
int nmbin = 11;
float logMvir_min= 12.0;
float logMvir_max= 16.0;
cosmo cosm_model(CP.H0, CP.Omega_M, CP.Omega_b, CP.Omega_k, CP.wt);
float z, Mvir, x;
std::vector<float> z_fft, M_fft, xlist;
/* set up for redshift, virial mass, radius bin */
//redshift
for(int i=0;i<nzbin;i++){
z = (log(zmax)-log(zmin))/(nzbin-1)*(float)(1.*i) + log(zmin);
z = exp(z);
z_fft.push_back(z);
}
//virial mass (Bryan & Norman) in [Msun], not in [Msun/h]
for(int i=0;i<nmbin;i++){
Mvir = (logMvir_max-logMvir_min)/(nmbin-1)*(float)(1.*i) + logMvir_min;
Mvir = pow(10.0, Mvir);
M_fft.push_back(Mvir);
}
//radius in unit of R500, x = r/R500
float xmin = 1e-4;
float xmax = 100.0;
for(int i=0;i<Nx;i++){
x = (log10(xmax)-log10(xmin))/Nx*(float)(1.*i+0.5) + log10(xmin);
x = pow(10.0, x);
xlist.push_back(x);
}
set_FFTlog_param();
double dlog_ell = (3.-(-5.))/(Nx-1);
double tab_l_ls[Nx];
double bin[Nx];
double tab_yl_int[Nx];
double flux[nmbin][nzbin];
double *tab_Fourier = new double[Nx * nzbin * nmbin];
double *tab_r500 = new double[nzbin * nmbin];
for(int i=0;i<Nx;i++){
tab_l_ls[i] = -5.0+(double)(i)*dlog_ell;
bin[i] = pow(10., tab_l_ls[i]);
}
for(int i=0;i<nzbin;i++){
//fprintf(stdout, ".");fflush(stdout);
for(int j=0;j<nmbin;j++){
//cout << zlist[i] << " " << Mlist[j] << endl;
//flux[i][j] = calc_Flender_xray_flux (cosm_model, z_fft[i], M_fft[j], xlist); //ergs/s/cm^2
std::vector<double> pressure;
pressure = calc_Flender_pressure_profile(cosm_model, z_fft[i], M_fft[j], xlist);
tab_r500[j+nmbin*i] = R500_here; // in Mpc;
double yp1 = 1.e31;
double ypn = 1.e31;
Nspline=0;
for(int k=0;k<Nx;k++){
if(pressure[k] > 0){
Nspline += 1;
}
}
if(Nspline > 2){
int id =0;
for(int k=0;k<Nx;k++){
if(pressure[k] > 0){
xp[id] = log10(xlist[k]);
yp[id] = log10(factor*pressure[k]);
id += 1;
}
}
double xout = pow(10., xp[Nspline-1]);
spline(xp-1, yp-1, Nspline, yp1, ypn, yp2-1);
FFT_density_profile(tab_yl_int, bin, Nx);
}else{
for(int k=0;k<Nx;k++) tab_yl_int[k] = 0.0;
}
for(int k=0;k<Nx;k++) {
tab_Fourier[k + Nx * ( j + nmbin * i)] = tab_yl_int[k];
}
}
}
/* Start computing a halo model */
int nd = x_input.get_nd();
if (nd != 1)
throw std::runtime_error("a must be 1-dimensional");
size_t nsh = x_input.shape(0);
if (x_input.get_dtype() != npy::dtype::get_builtin<double>())
throw std::runtime_error("a must be float64 array");
auto xshape = x_input.get_shape();
auto xstrides = x_input.get_strides();
int Nbin=xshape[0];
double lbin[Nbin];
double signal[Nbin];
for (int i = 0; i < xshape[0]; ++i) {
lbin[i] = *reinterpret_cast<double *>(x_input.get_data() + i * xstrides[0]);
}
double yp1 = 1.e31;
double ypn = 1.e31;
int Nell = Nx;
double tab_fc_int[Nell], tab_fc_int2[Nell];
float dlnz = (log(zmax)-log(zmin))/(nzbin-1);
float dlogm = (logMvir_max-logMvir_min)/(nmbin-1);
double zlist[nzbin];
double cl_xx_1_int_z[nzbin], cl_xx_1_int_z2[nzbin];
double cl_xx_2_int_z[nzbin], cl_xx_2_int_z2[nzbin];
double mlist[nmbin];
double cl_xx_1_int_m[nmbin], cl_xx_1_int_m2[nmbin];
double cl_xx_2_int_m[nmbin], cl_xx_2_int_m2[nmbin];
for(int iz=0;iz<nzbin;iz++){
cl_xx_1_int_z[iz] = 0.0;
cl_xx_2_int_z[iz] = 0.0;
cl_xx_1_int_z2[iz] = 0.0;
cl_xx_2_int_z2[iz] = 0.0;
}
for(int jm=0;jm<nmbin;jm++){
cl_xx_1_int_m[jm] = 0.0;
cl_xx_2_int_m[jm] = 0.0;
cl_xx_1_int_m2[jm] = 0.0;
cl_xx_2_int_m2[jm] = 0.0;
}
for(int i=0;i<Nbin;i++){
double ell_bin = lbin[i];
double cl_xx_1=0.0, cl_xx_2=0.0;
for(int iz=0;iz<nzbin;iz++){
double zhere = exp(dlnz*(double)(1.*iz) + log(zmin));
zlist[iz] = log(zhere);
double covd = chi_fast(zhere);
double dVdz = covd*covd *C*CP.H0/100.0/H_z(zhere);
double calc_k = ell_bin/covd;
double gfac = (growth(1./(1+zhere))/growth(1.0));
double Pk = gfac*gfac*PowerSpec(calc_k);
for(int jm=0;jm<nmbin;jm++){
//if ( flux[iz][jm] >= 0.0 ) {
double logMvir = dlogm*(double)(1.*jm) + logMvir_min;
mlist[jm] = logMvir;
double Mvir = pow(10., logMvir); // in the unit of Msun/
double r500 = tab_r500[jm+nmbin*iz];
double ells = covd/(1+zhere)/r500; // = ell_500
double l_ls = ell_bin/ells;
for(int il=0;il<Nell;il++){
tab_fc_int[il] = tab_Fourier[il + Nell * (jm + nmbin * iz)] * sigma_T/m_elect * megapc ; // 1/Mpc
}
double yl;
int index;
index = -1;
for(int il=0;il<Nell-1;il++){
if(tab_l_ls[il] < log10(l_ls) && log10(l_ls) < tab_l_ls[il+1]){
index = il;
}
}
if(index < 0){
yl = 0;
} else {
yl = (tab_fc_int[index+1]-tab_fc_int[index])/(tab_l_ls[index+1]-tab_l_ls[index])*(log10(l_ls)-tab_l_ls[index]) + tab_fc_int[index];
yl = yl * 4*M_PI*(r500)/ells/ells; //
}
//double m200m = M_vir_to_M_delta(zhere, Mvir, 200.0);
double mf = dndlogm_fast(log10(Mvir), zhere);
double b = halo_bias_fast(log10(Mvir), zhere);
cl_xx_1_int_m[jm] = mf * yl * yl;
cl_xx_2_int_m[jm] = mf * b * yl;
//} else {
// cl_xx_1_int_m[jm] = 0.0;
// cl_xx_2_int_m[jm] = 0.0;
//}
//fprintf(stdout,"z, mvir, mf, b = %f %e %e %e\n", zhere, Mvir, mf,b);
}
spline(mlist-1, cl_xx_1_int_m-1, nmbin, yp1, ypn, cl_xx_1_int_m2-1);
spline(mlist-1, cl_xx_2_int_m-1, nmbin, yp1, ypn, cl_xx_2_int_m2-1);
double oneh_xx, twoh_xx;
//double tab_spline_and_integral(int Nbin, double *xlist, double *ylist, double *zlist)
oneh_xx = tab_spline_and_integral(nmbin, mlist, cl_xx_1_int_m, cl_xx_1_int_m2);
twoh_xx = tab_spline_and_integral(nmbin, mlist, cl_xx_2_int_m, cl_xx_2_int_m2);
cl_xx_1_int_z[iz] = zhere * dVdz * oneh_xx;
cl_xx_2_int_z[iz] = zhere * dVdz * twoh_xx * twoh_xx * Pk;
//fprintf(stdout,"iz= %d %e %e\n", iz,cl_xx_1_int_z[iz], cl_xx_2_int_z[iz] );
}
spline(zlist-1, cl_xx_1_int_z-1, nzbin, yp1, ypn, cl_xx_1_int_z2-1);
spline(zlist-1, cl_xx_2_int_z-1, nzbin, yp1, ypn, cl_xx_2_int_z2-1);
cl_xx_1 = tab_spline_and_integral(nzbin, zlist, cl_xx_1_int_z, cl_xx_1_int_z2);
cl_xx_2 = tab_spline_and_integral(nzbin, zlist, cl_xx_2_int_z, cl_xx_2_int_z2);
signal[i] = cl_xx_1 + cl_xx_2;
//printf("%f %e %e\n", ell_bin, cl_xx_1, cl_xx_2);
if(cl_xx_1 != cl_xx_1 || cl_xx_2 != cl_xx_2) signal[i]=0;
}
free_FFTdata();
delete[] tab_Fourier;
delete[] tab_r500;
vector<double> v;
for(int i=0;i<Nbin;i++) v.push_back(signal[i]);
Py_intptr_t shape[1] = { v.size() };
npy::ndarray result = npy::zeros(1, shape, npy::dtype::get_builtin<double>());
copy(v.begin(), v.end(), reinterpret_cast<double*>(result.get_data()));
return result;
}
npy::ndarray return_pressure_profile(npy::ndarray x_input, double z, double Mvir){
cosmo cosm_model(CP.H0, CP.Omega_M, CP.Omega_b, CP.Omega_k, CP.wt);
cout << "computing pressure profile" << endl;
int nd = x_input.get_nd();
if (nd != 1)
throw std::runtime_error("a must be 1-dimensional");
size_t nsh = x_input.shape(0);
if (x_input.get_dtype() != npy::dtype::get_builtin<double>())
throw std::runtime_error("a must be float64 array");
auto xshape = x_input.get_shape();
auto xstrides = x_input.get_strides();
//int Nbin=xshape[0];
int Nbin = x_input.shape(0);
/*
double* input_ptr = reinterpret_cast<double*>(input.get_data());
std::vector<double> v(input_size);
for (int i = 0; i < input_size; ++i)
v[i] = *(input_ptr + i);
*/
double lbin[Nbin];
std::vector<float> xlist(Nbin);
for (int i = 0; i < Nbin; ++i) {
lbin[i] = *reinterpret_cast<double *>(x_input.get_data() + i * xstrides[0]);
xlist[i] = (float)lbin[i];
}
std::vector<double> pressure;
pressure = calc_Flender_pressure_profile(cosm_model, z, Mvir, xlist);
Py_intptr_t shape[1] = { pressure.size() };
npy::ndarray result = npy::zeros(1, shape, npy::dtype::get_builtin<double>());
copy(pressure.begin(), pressure.end(), reinterpret_cast<double*>(result.get_data()));
return result;
}
double return_Ysz(double z, double Mvir){
cosmo cosm_model(CP.H0, CP.Omega_M, CP.Omega_b, CP.Omega_k, CP.wt);
std::vector<float> xlist;
//radius in unit of R500, x = r/R500
float xmin = 1e-4;
float xmax = 10.0;
float x;
for(int i=0;i<Nx;i++){
x = (log10(xmax)-log10(xmin))/Nx*(float)(1.*i+0.5) + log10(xmin);
x = pow(10.0, x);
xlist.push_back(x);
}
double Ysz;
// Ysz in Mpc^2
Ysz= calc_Flender_Ysz (cosm_model, z, Mvir, xlist);
return Ysz;
}
BOOST_PYTHON_MODULE( yy_power ){
Py_Initialize();
npy::initialize();
py::def("init_cosmology", init_cosmology);
py::def("free_cosmology", free_cosmology);
py::def("set_Flender_params", set_Flender_params);
py::def("return_yy_power", return_yy_power);
py::def("return_Ysz", return_Ysz);
py::def("return_pressure_profile", return_pressure_profile);
}
double calc_Flender_Ysz (cosmo cosm_model, float z, float Mvir, std::vector<float> x){
float conc_norm = F.A_C;
float conc_mass_norm = 1.0;
float ad_index = 5.0; // Gamma = 1+1./ad_index in arXiv:1706.08972
/*
float delta_rel = 0.18, delta_rel_n = 0.8, delta_rel_zslope = 0.5; // delta_rel = alpha_0, delta_rel_n = n_nt, delta_rel_zslope = beta in Shaw et al 2010
float eps_fb = 3.97e-6; // epsilon_f in arXiv:1706.08972
float eps_dm = 0.0; // epsilon_DM in arXiv:1706.08972
float fs_0 = 0.026; // f_star in arXiv:1706.08972
float fs_alpha = 0.12; // S_star in arXiv:1706.08972
*/
float delta_rel = F.alpha0, delta_rel_n = F.n_nt, delta_rel_zslope = F.beta;
float eps_fb = F.eps_f;
float eps_dm = F.eps_DM;
float fs_0 = F.f_star;
float fs_alpha = F.S_star;
float gamma_mod0 = F.gamma_mod0;
float gamma_mod_zslope = F.gamma_mod_zslope;
float x_break = F.x_break;
float x_smooth = F.x_smooth;
float clump0 = F.clump0;
float clump_zslope = F.clump_zslope;
float x_clump = F.x_clump;
float alpha_clump1 = F.alpha_clump1;
float alpha_clump2 = F.alpha_clump2;
int pturbrad = 2;
bool verbose = false;
float Rvir, M500, R500, Rscale, conc, cosmic_t, cosmic_t0;
float Omega_M = cosm_model.get_Omega_M();
float Omega_b = cosm_model.get_Omega_b();
float h =cosm_model.get_H0()/100.0;
float E;
// set cluster overdensity
// this is the overdensity within which mass defined (i.e. \Delta)
// set to -1.0 for virial radius, or 200 for M200 (rhocrit)
float overden_id = -1.0; // 200 for delta=200 rho-c , -1 for delta=vir x rho-c
int relation = 3; // concentration relation
float rcutoff = 2.0;
float Redshift = z;
cosmic_t = cosm_model.cosmic_time(Redshift);
cosmic_t0 = cosm_model.cosmic_time(0.0);
E = cosm_model.Efact(Redshift);
cluster nfwclus(Mvir, Redshift, overden_id, relation, cosm_model);
float cvir;
nfwclus.concentration(conc_norm, conc_mass_norm); // set halo concentration using M-c relation of Duffy et al (08)
//cvir = conc_norm * c_vir_DK15_fast(z, Mvir);
//nfwclus.set_conc(cvir);
cvir = nfwclus.get_conc();
M500 = nfwclus.get_mass_overden(500.0);// Msun
R500 = nfwclus.get_rad_overden(500.0);// (physical) Mpc
Rvir = nfwclus.get_radius();
//cout << M500 <<' ' << R500 << ' ' << cvir << endl;
gas_model icm_mod(delta_rel, ad_index, eps_fb, eps_dm, fs_0, fs_alpha, pturbrad, delta_rel_zslope, delta_rel_n);
icm_mod.calc_fs(M500, Omega_b/Omega_M, cosmic_t0, cosmic_t);
icm_mod.evolve_pturb_norm(Redshift, rcutoff);
icm_mod.set_nfw_params(Mvir, Rvir, nfwclus.get_conc(), nfwclus.get_rhoi(), R500);
icm_mod.set_mgas_init(Omega_b/Omega_M);
icm_mod.findxs();
icm_mod.solve_gas_model(verbose, 1e-5);
//double Rmax = icm_mod.thermal_pressure_outer_rad()*R500;
double Rmax = R500;
//double Yanl = icm_mod.calc_Y(R500, Rvir, Rmax);
double r, pres, dYsz;
double Ysz;
float npoly_mod, gamma_mod;
gamma_mod = gamma_mod0 * pow((1.0+Redshift),gamma_mod_zslope);
npoly_mod = 1.0/(gamma_mod - 1.0 );
double dvol[x.size()];
for(int xi=0;xi<x.size();xi++){
r = (double) x[xi]*R500;
if ( xi == 0 ) {
dvol[xi] = 4.0*M_PI*pow(r, 3.0)/3.0;
} else {
dvol[xi] = 4.0*M_PI*pow(r, 3.0)/3.0 - dvol[xi-1];
}
}
Ysz = 0.0;
for(int xi=0;xi<x.size();xi++){
// r in Mpc;/
r = (double) x[xi]*R500;
if(r >= Rmax ){
pres = 0.0;
} else{
pres = icm_mod.returnPth_mod2(r, R500, x_break, npoly_mod, x_smooth); //keV cm^-3
pres = pres * factor;
dYsz= pres * dvol[xi] ; //keV cm^-3 Mpc^3
Ysz = Ysz + dYsz;
}
}
Ysz *= sigma_T/m_elect; // cm^-1 Mpc^3
Ysz *= megapc;
return Ysz;
}
std::vector<double> calc_Flender_pressure_profile(cosmo cosm_model, float z, float Mvir, std::vector<float> x){
float conc_norm = F.A_C;
float conc_mass_norm = 1.0;
float ad_index = 5.0; // Gamma = 1+1./ad_index in arXiv:1706.08972
/*
float delta_rel = 0.18, delta_rel_n = 0.8, delta_rel_zslope = 0.5; // delta_rel = alpha_0, delta_rel_n = n_nt, delta_rel_zslope = beta in Shaw et al 2010
float eps_fb = 3.97e-6; // epsilon_f in arXiv:1706.08972
float eps_dm = 0.0; // epsilon_DM in arXiv:1706.08972
float fs_0 = 0.026; // f_star in arXiv:1706.08972
float fs_alpha = 0.12; // S_star in arXiv:1706.08972
*/
float delta_rel = F.alpha0, delta_rel_n = F.n_nt, delta_rel_zslope = F.beta;
float eps_fb = F.eps_f;
float eps_dm = F.eps_DM;
float fs_0 = F.f_star;
float fs_alpha = F.S_star;
float gamma_mod0 = F.gamma_mod0;
float gamma_mod_zslope = F.gamma_mod_zslope;
float x_break = F.x_break;
float x_smooth = F.x_smooth;
float clump0 = F.clump0;
float clump_zslope = F.clump_zslope;
float x_clump = F.x_clump;
float alpha_clump1 = F.alpha_clump1;
float alpha_clump2 = F.alpha_clump2;
int pturbrad = 2;
bool verbose = false;
float Rvir, M500, R500, Rscale, conc, cosmic_t, cosmic_t0;
float Omega_M = cosm_model.get_Omega_M();
float Omega_b = cosm_model.get_Omega_b();
float h =cosm_model.get_H0()/100.0;
float E;
// set cluster overdensity
// this is the overdensity within which mass defined (i.e. \Delta)
// set to -1.0 for virial radius, or 200 for M200 (rhocrit)
float overden_id = -1.0; // 200 for delta=200 rho-c , -1 for delta=vir x rho-c
int relation = 3; // concentration relation
float rcutoff = 2.0;
float Redshift = z;
cosmic_t = cosm_model.cosmic_time(Redshift);
cosmic_t0 = cosm_model.cosmic_time(0.0);
E = cosm_model.Efact(Redshift);
cluster nfwclus(Mvir, Redshift, overden_id, relation, cosm_model);
//M500 = nfwclus.get_mass_overden(500.0);// Msun
//R500 = nfwclus.get_rad_overden(500.0);// (physical) Mpc
//Rvir = nfwclus.get_radius();
float cvir;
nfwclus.concentration(conc_norm, conc_mass_norm); // set halo concentration using M-c relation of Duffy et al (08)
//cvir = conc_norm * c_vir_DK15_fast(z, Mvir*h);
//nfwclus.set_conc(cvir);
cvir = nfwclus.get_conc();
M500 = nfwclus.get_mass_overden(500.0);// Msun
R500 = nfwclus.get_rad_overden(500.0);// (physical) Mpc
Rvir = nfwclus.get_radius();
R500_here = R500; // physical Mpc
//cout << M500 << " " << R500 << " " << Rvir << endl;
gas_model icm_mod(delta_rel, ad_index, eps_fb, eps_dm, fs_0, fs_alpha, pturbrad, delta_rel_zslope, delta_rel_n);
icm_mod.calc_fs(M500, Omega_b/Omega_M, cosmic_t0, cosmic_t);
icm_mod.evolve_pturb_norm(Redshift, rcutoff);
icm_mod.set_nfw_params(Mvir, Rvir, nfwclus.get_conc(), nfwclus.get_rhoi(), R500);
icm_mod.set_mgas_init(Omega_b/Omega_M);
icm_mod.findxs();
icm_mod.solve_gas_model(verbose, 1e-5);
double P500 = icm_mod.return_P500_arnaud10(M500, E);
//double Rmax = icm_mod.thermal_pressure_outer_rad()*R500;
double Rmax = 3.0*R500;
//double Yanl = icm_mod.calc_Y(R500, Rvir, Rmax);
double r, pres;
std::vector<double> profile;
// redshift dependence in solid angle
double fac = 4.0*M_PI*pow(1.0+Redshift, 4.0); // in steradians
float npoly_mod, gamma_mod;
gamma_mod = gamma_mod0 * pow((1.0+Redshift),gamma_mod_zslope);
npoly_mod = 1.0/(gamma_mod - 1.0 );
for(int xi=0;xi<x.size();xi++){
r = (double) x[xi]*R500;
if(r >= Rmax){pres = 0.0;}
else{
/*
double ngas,pressure, kT;
pressure = icm_mod.returnPth_mod2(r, R500, x_break, npoly_mod, x_smooth);
ngas = icm_mod.return_ngas_mod(r, R500, x_break, npoly_mod);
kT = pressure/ngas;
*/
pres = icm_mod.returnPth_mod2(r, R500, x_break, npoly_mod, x_smooth); //keV cm^-3
}
profile.push_back(pres);
}
return profile;
}
std::vector<double> calc_Flender_xray_emissivity_profile(cosmo cosm_model, float z, float Mvir, std::vector<float> x){
float conc_norm = F.A_C;
float conc_mass_norm = 1.0;
float ad_index = 5.0; // Gamma = 1+1./ad_index in arXiv:1706.08972
/*
float delta_rel = 0.18, delta_rel_n = 0.8, delta_rel_zslope = 0.5; // delta_rel = alpha_0, delta_rel_n = n_nt, delta_rel_zslope = beta in Shaw et al 2010
float eps_fb = 3.97e-6; // epsilon_f in arXiv:1706.08972
float eps_dm = 0.0; // epsilon_DM in arXiv:1706.08972
float fs_0 = 0.026; // f_star in arXiv:1706.08972
float fs_alpha = 0.12; // S_star in arXiv:1706.08972
*/
float delta_rel = F.alpha0, delta_rel_n = F.n_nt, delta_rel_zslope = F.beta;
float eps_fb = F.eps_f;
float eps_dm = F.eps_DM;
float fs_0 = F.f_star;
float fs_alpha = F.S_star;
float gamma_mod0 = F.gamma_mod0;
float gamma_mod_zslope = F.gamma_mod_zslope;
float x_break = F.x_break;
float x_smooth = F.x_smooth;
float clump0 = F.clump0;
float clump_zslope = F.clump_zslope;
float x_clump = F.x_clump;
float alpha_clump1 = F.alpha_clump1;
float alpha_clump2 = F.alpha_clump2;
int pturbrad = 2;
bool verbose = false;
float Rvir, M500, R500, Rscale, conc, cosmic_t, cosmic_t0;
float Omega_M = cosm_model.get_Omega_M();
float Omega_b = cosm_model.get_Omega_b();
float h =cosm_model.get_H0()/100.0;
float E;
// set cluster overdensity
// this is the overdensity within which mass defined (i.e. \Delta)
// set to -1.0 for virial radius, or 200 for M200 (rhocrit)
float overden_id = -1.0; // 200 for delta=200 rho-c , -1 for delta=vir x rho-c
int relation = 3; // concentration relation
float rcutoff = 2.0;
float Redshift = z;
cosmic_t = cosm_model.cosmic_time(Redshift);
cosmic_t0 = cosm_model.cosmic_time(0.0);
E = cosm_model.Efact(Redshift);
cluster nfwclus(Mvir, Redshift, overden_id, relation, cosm_model);
//nfwclus.concentration(conc_norm, conc_mass_norm); // set halo concentration using M-c relation of Duffy et al (08)
//M500 = nfwclus.get_mass_overden(500.0);// Msun
//R500 = nfwclus.get_rad_overden(500.0);// (physical) Mpc
//Rvir = nfwclus.get_radius();
float cvir = conc_norm * c_vir_DK15_fast(z, Mvir*h);
nfwclus.set_conc(cvir);
M500 = nfwclus.get_mass_overden(500.0);// Msun
R500 = nfwclus.get_rad_overden(500.0);// (physical) Mpc
Rvir = nfwclus.get_radius();
R500_here = R500 * h; // physical Mpc/h
//cout << M500 << " " << R500 << " " << Rvir << endl;
gas_model icm_mod(delta_rel, ad_index, eps_fb, eps_dm, fs_0, fs_alpha, pturbrad, delta_rel_zslope, delta_rel_n);
icm_mod.calc_fs(M500, Omega_b/Omega_M, cosmic_t0, cosmic_t);
icm_mod.evolve_pturb_norm(Redshift, rcutoff);
icm_mod.set_nfw_params(Mvir, Rvir, nfwclus.get_conc(), nfwclus.get_rhoi(), R500);
icm_mod.set_mgas_init(Omega_b/Omega_M);
icm_mod.findxs();
icm_mod.solve_gas_model(verbose, 1e-5);
//double Rmax = icm_mod.thermal_pressure_outer_rad()*R500;
double Rmax = 3.0*R500;
//double Yanl = icm_mod.calc_Y(R500, Rvir, Rmax);
double r, emi;
std::vector<double> emission;
// redshift dependence in solid angle
double fac = 4.0*M_PI*pow(1.0+Redshift, 4.0); // in steradians
float npoly_mod, gamma_mod;
gamma_mod = gamma_mod0 * pow((1.0+Redshift),gamma_mod_zslope);
npoly_mod = 1.0/(gamma_mod - 1.0 );
for(int xi=0;xi<x.size();xi++){
r = (double) x[xi]*R500;
if(r >= Rmax){emi = 0.0;}
else{
/*
double ngas,pressure, kT;
pressure = icm_mod.returnPth_mod2(r, R500, x_break, npoly_mod, x_smooth);
ngas = icm_mod.return_ngas_mod(r, R500, x_break, npoly_mod);
kT = pressure/ngas;
*/
double ngas,pressure, kT, clump, clump1;
pressure = icm_mod.returnPth_mod2(r, R500, x_break, npoly_mod, x_smooth); //keV cm^-3
ngas = icm_mod.return_ngas_mod(r, R500, x_break, npoly_mod); //cm^-3
kT = pressure/ngas; // keV
clump1 = icm_mod.return_clumpf(r, R500, clump0, x_clump, alpha_clump1, alpha_clump2) - 1.0;
clump1 *= pow(1.+Redshift, clump_zslope);
clump = 1.0 + clump1;
if (clump < 1.0) clump = 1.0;
ngas *= sqrt(clump);
emi = icm_mod.return_xray_emissivity(ngas, kT, Redshift); // ergs/s/cm^3
//emi = icm_mod.calc_xray_emissivity(r, R500, Redshift); // count/s/cm^3
//printf("r, pressure, kT, ngas, emi = %f, %e, %e, %e, %e\n", r, pressure, kT, ngas, emi);
}
//if(emi < 1e-50){emi = 0.0;}
emi = emi/fac; // ergs/s/cm^3/str
//printf("emission = %e\n", emi);
//cout << r << " " << emi <<endl;
emission.push_back(emi);
}
return emission;
}
std::vector<double> calc_Shaw_xray_emissivity_profile(cosmo cosm_model, float z, float Mvir, std::vector<float> x){
float conc_norm = S.A_C;
float conc_mass_norm = 1.0;
float ad_index = 5.0; // Gamma = 1+1./ad_index in arXiv:1706.08972
/*
float delta_rel = 0.18, delta_rel_n = 0.8, delta_rel_zslope = 0.5; // delta_rel = alpha_0, delta_rel_n = n_nt, delta_rel_zslope = beta in Shaw et al 2010
float eps_fb = 3.97e-6; // epsilon_f in arXiv:1706.08972
float eps_dm = 0.0; // epsilon_DM in arXiv:1706.08972
float fs_0 = 0.026; // f_star in arXiv:1706.08972
float fs_alpha = 0.12; // S_star in arXiv:1706.08972
*/
float delta_rel = S.alpha0, delta_rel_n = S.n_nt, delta_rel_zslope = S.beta;
float eps_fb = S.eps_f;
float eps_dm = S.eps_DM;
float fs_0 = S.f_star;
float fs_alpha = S.S_star;
int pturbrad = 2;
bool verbose = false;
float Rvir, M500, R500, Rscale, conc, cosmic_t, cosmic_t0;
float Omega_M = cosm_model.get_Omega_M();
float Omega_b = cosm_model.get_Omega_b();
float h =cosm_model.get_H0()/100.0;
float E;
// set cluster overdensity
// this is the overdensity within which mass defined (i.e. \Delta)
// set to -1.0 for virial radius, or 200 for M200 (rhocrit)
float overden_id = -1.0; // 200 for delta=200 rho-c , -1 for delta=vir x rho-c
int relation = 3; // concentration relation
float rcutoff = 2.0;
float Redshift = z;
cosmic_t = cosm_model.cosmic_time(Redshift);
cosmic_t0 = cosm_model.cosmic_time(0.0);
E = cosm_model.Efact(Redshift);
cluster nfwclus(Mvir, Redshift, overden_id, relation, cosm_model);
//nfwclus.concentration(conc_norm, conc_mass_norm); // set halo concentration using M-c relation of Duffy et al (08)
//M500 = nfwclus.get_mass_overden(500.0);// Msun
//R500 = nfwclus.get_rad_overden(500.0);// (physical) Mpc
//Rvir = nfwclus.get_radius();
float cvir = conc_norm * c_vir_DK15_fast(z, Mvir*h);
nfwclus.set_conc(cvir);
M500 = nfwclus.get_mass_overden(500.0);// Msun
R500 = nfwclus.get_rad_overden(500.0);// (physical) Mpc
Rvir = nfwclus.get_radius();
//cout << M500 << " " << R500 << " " << Rvir << endl;
gas_model icm_mod(delta_rel, ad_index, eps_fb, eps_dm, fs_0, fs_alpha, pturbrad, delta_rel_zslope, delta_rel_n);
icm_mod.calc_fs(M500, Omega_b/Omega_M, cosmic_t0, cosmic_t);
icm_mod.evolve_pturb_norm(Redshift, rcutoff);
icm_mod.set_nfw_params(Mvir, Rvir, nfwclus.get_conc(), nfwclus.get_rhoi(), R500);
icm_mod.set_mgas_init(Omega_b/Omega_M);
icm_mod.findxs();
icm_mod.solve_gas_model(verbose, 1e-5);
//double Rmax = icm_mod.thermal_pressure_outer_rad()*R500;
double Rmax = 3.0*R500;
//double Yanl = icm_mod.calc_Y(R500, Rvir, Rmax);
double r, emi;
std::vector<double> emission;
double fac = 4.0*M_PI*180.0*3600.0/M_PI *180.0*3600.0/M_PI;
for(int xi=0;xi<x.size();xi++){
r = (double) x[xi]*R500;
if(r >= Rmax){emi = 0.0;}
else{emi = icm_mod.return_xray_emissivity(r, R500, Redshift);}
//if(emi < 1e-50){emi = 0.0;}
emi = emi/fac/pow(1.+Redshift, 4.);
//cout << r << " " << emi <<endl;
emission.push_back(emi);
}
return emission;
}
/*
double x_l_integral_int_x(double x, double l_ls){
double res;
double x2px;
if(x > pow(10., xp[0]) && x < pow(10., xp[Nspline-1])){
double logx = log10(x);
splint(xp-1, yp-1, yp2-1, Nspline, logx, &x2px);
x2px = pow(10., x2px) *x*x;
}else{
return 0;
}
double kernel;
double lx = l_ls*x;
if(lx < 1e-2){
kernel = 1.0-lx*lx/6.;
}else{
kernel = sin(lx)/(lx);
}
res =x2px*kernel;
return res;
}