Skip to content

Commit

Permalink
Improved and fixed bug. (#17)
Browse files Browse the repository at this point in the history
* bug fixed

* Improved stability of 'tauX' and 'Mass_limit' calculation

* Conflict fixed

* (1) Added function to compute the volume filling factor Q, (2) Added python script to generate a summary plot which are a lightcone slice, the brightness temperature and the power spectrum at k=0.1Mpc^-1 (3) Improved stability of 'tauX' and 'Mass_limit' calculation and (4) Updated Out-of-box-Output

* Updated 'HII_ROUND_ERR' to avoid discontinuous of the redshift evolution in PS

* Replaced the function 'Mass_limit_bisection' with a simple analytic form, and fixed the interpolation in high density region for the SFRD calculation.

* Fixed bug when using 'SUBCELL_RSD' without 'USE_TS_IN_21CM' in delta_T.c.
  • Loading branch information
jaehongpark00 authored and andreimesinger committed Aug 29, 2019
1 parent cbae4dc commit 94419d1
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 78 deletions.
66 changes: 12 additions & 54 deletions Cosmo_c_files/ps.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ void initialiseGL_Nion(int n, float M_TURN, float M_Max);
void Nion_Spline_density(float Overdensity, float *splined_value);
void initialise_Nion_spline(float z, float Mmax, float MassTurnover, float Alpha_star, float Alpha_esc, float Fstar10, float Fesc10, float Mlim_Fstar, float Mlim_Fesc);

float Mass_limit (float logM, float PL, float FRAC);
void bisection(float *x, float xlow, float xup, int *iter);
float Mass_limit_bisection(float Mmin, float Mmax, float PL, float FRAC);
float Mass_limit (float PL, float FRAC);

static double z_val[zpp_interp_points],Nion_z_val[zpp_interp_points]; // For Ts.c
static double z_X_val[zpp_interp_points],SFRD_val[zpp_interp_points];
Expand Down Expand Up @@ -1170,54 +1168,14 @@ void initialiseSplinedSigmaM(float M_Min, float M_Max)
/* New in v2 - part 4 of 4 start */

/*
FUNCTION Mass_limit_bisection(M_min, M_max, power-law, normalization)
Compute a threshold of halo mass above/below which f_{\ast}(M)/f_{esc}(M) exceeds unity/zero.
FUNCTION Mass_limit(power-law, normalization)
Compute a threshold of a halo mass at which the stellar mass fraction (the escape fraction)
exceeds unity. If the fraction is larger than unity, set the fraction is unity.
*/
float Mass_limit (float logM, float PL, float FRAC) {
return FRAC*pow(pow(10.,logM)/1e10,PL);
}
void bisection(float *x, float xlow, float xup, int *iter){
*x=(xlow + xup)/2.;
++(*iter);
float Mass_limit (float PL, float FRAC) {
return 1e10*pow(1./FRAC,1./PL);
}

float Mass_limit_bisection(float Mmin, float Mmax, float PL, float FRAC){
int i, iter, max_iter=200;
float rel_tol=0.001;
float logMlow, logMupper, x, x1;
iter = 0;
logMlow = log10(Mmin);
logMupper = log10(Mmax);

if (PL < 0.) {
if (Mass_limit(logMlow,PL,FRAC) <= 1.) {
return Mmin;
}
}
else if (PL > 0.) {
if (Mass_limit(logMupper,PL,FRAC) <= 1.) {
return Mmax;
}
}
else
return 0;
bisection(&x, logMlow, logMupper, &iter);
do {
if((Mass_limit(logMlow,PL,FRAC)-1.)*(Mass_limit(x,PL,FRAC)-1.) < 0.)
logMupper = x;
else
logMlow = x;
bisection(&x1, logMlow, logMupper, &iter);
if(fabs(x1-x) < rel_tol) {
return pow(10.,x1);
}
x = x1;
}
while(iter < max_iter);
printf("\n Failed to find a mass limit to regulate stellar fraction/escape fraction is between 0 and 1.\n");
printf(" The solution does not converge or iterations are not sufficient\n");
return -1;
}

/*
FUNCTION Nion_ST(z, Mturn)
Expand Down Expand Up @@ -1515,8 +1473,8 @@ void initialise_Nion_ST_spline(int Nbin, float zmin, float zmax, float MassTurn,
float Mmin = MassTurn/50., Mmax = 1e16;
float Mlim_Fstar, Mlim_Fesc;

Mlim_Fstar = Mass_limit_bisection(Mmin, Mmax, Alpha_star, Fstar10);
Mlim_Fesc = Mass_limit_bisection(Mmin, Mmax, Alpha_esc, Fesc10);
Mlim_Fstar = Mass_limit(Alpha_star, Fstar10);
Mlim_Fesc = Mass_limit(Alpha_esc, Fesc10);

Nion_z_spline_acc = gsl_interp_accel_alloc ();
Nion_z_spline = gsl_spline_alloc (gsl_interp_cspline, Nbin);
Expand All @@ -1539,7 +1497,7 @@ void initialise_SFRD_ST_spline(int Nbin, float zmin, float zmax, float MassTurn,
float Mmin = MassTurn/50., Mmax = 1e16;
float Mlim_Fstar;

Mlim_Fstar = Mass_limit_bisection(Mmin, Mmax, Alpha_star, Fstar10);
Mlim_Fstar = Mass_limit(Alpha_star, Fstar10);

SFRD_ST_z_spline_acc = gsl_interp_accel_alloc ();
SFRD_ST_z_spline = gsl_spline_alloc (gsl_interp_cspline, Nbin);
Expand Down Expand Up @@ -1568,7 +1526,7 @@ void initialise_SFRD_Conditional_table(int Nsteps_zp, int Nfilter, float z[], do

Mmin = MassTurnover/50;
Mmax = RtoM(R[Nfilter-1]);
Mlim_Fstar = Mass_limit_bisection(Mmin, Mmax, Alpha_star, Fstar10);
Mlim_Fstar = Mass_limit(Alpha_star, Fstar10);
initialiseSplinedSigmaM(Mmin,Mmax);
fprintf(stderr, "In initialise_Fcollz_SFR_Conditional_table: Rmin = %6.4f, Rmax = %6.4f, Mmin = %.4e, Mmax = %.4e\n",
R[0],R[Nfilter-1],RtoM(R[0]),RtoM(R[Nfilter-1]));
Expand Down Expand Up @@ -1684,8 +1642,8 @@ void initialise_Q_value_spline(int NoRec, float MassTurn, float Alpha_star, floa
z_arr = calloc(Nmax,sizeof(double));
Q_arr = calloc(Nmax,sizeof(double));

Mlim_Fstar = Mass_limit_bisection(MassTurn/50., 1e16, Alpha_star, Fstar10);
Mlim_Fesc = Mass_limit_bisection(MassTurn/50., 1e16, Alpha_esc, Fesc10);
Mlim_Fstar = Mass_limit(Alpha_star, Fstar10);
Mlim_Fesc = Mass_limit(Alpha_esc, Fesc10);
ION_EFF_FACTOR = N_GAMMA_UV * Fstar10 * Fesc10;

a = a_start;
Expand Down
5 changes: 3 additions & 2 deletions Parameter_files/ANAL_PARAMS.H
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,10 @@
then find_HII_bubbles just prints a homogeneous xHI field
of 1's.
This is a new option in v1.1. Previous versions had a hardcoded value of 1e-15.
Previous versions had a value of 1e-3. In order to avoid discontinuous of redshift evolution in PS,
the threshold is changed to 1e-5, which is a hardcoded value.
*/
#define HII_ROUND_ERR (float) (1e-3)
#define HII_ROUND_ERR (float) (1e-5)


/*
Expand Down
4 changes: 2 additions & 2 deletions Programs/Ts.c
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ double freq_int_heat[NUM_FILTER_STEPS_FOR_Ts], freq_int_ion[NUM_FILTER_STEPS_FOR
// However, such densities should always be collapsed, so just set f_coll to unity.
// Additionally, the fraction of points in this regime relative to the entire simulation volume is extremely small.
//New
splint(Overdense_high_table-1,SFRD_z_high_table[R_ct]-1,second_derivs_Nion_zpp[R_ct]-1,NSFR_high,delNL0[R_ct][box_ct]*growth_zpp,&(fcoll));
splint(Overdense_high_table-1,SFRD_z_high_table[arr_num+R_ct]-1,second_derivs_Nion_zpp[R_ct]-1,NSFR_high,delNL0[R_ct][box_ct]*growth_zpp,&(fcoll));
}
else {
fcoll = 1.;
Expand Down Expand Up @@ -905,7 +905,7 @@ double freq_int_heat[NUM_FILTER_STEPS_FOR_Ts], freq_int_ion[NUM_FILTER_STEPS_FOR
}

/******** finally compute the redshift derivatives *************/
evolveInt(zp, curr_delNL0, freq_int_heat, freq_int_ion, freq_int_lya,
evolveInt(zp, arr_num, curr_delNL0, freq_int_heat, freq_int_ion, freq_int_lya,
COMPUTE_Ts, ans, dansdz);//, M_TURN,ALPHA_STAR,F_STAR10,T_AST);

//update quantities
Expand Down
59 changes: 44 additions & 15 deletions Programs/delta_T.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ int main(int argc, char ** argv){


/************ BEGIN INITIALIZATION ****************************/
if (!T_USE_VELOCITIES & SUBCELL_RSD){
fprintf(stderr, "'SUBCELL_RSD' uses velocities. You MUST turn on 'T_USE_VELOCITIES' to use 'SUBCELL_RSD'.\nAborting!\n");
return -1;
}

if (SHARP_CUTOFF) HALO_MASS_DEPENDENT_IONIZING_EFFICIENCY = 1;
max = -1e3;
min = 1e3;
Expand Down Expand Up @@ -338,29 +343,53 @@ int main(int argc, char ** argv){
fftwf_execute(plan);
fftwf_destroy_plan(plan);
fftwf_cleanup();

if(SUBCELL_RSD) {

// now add the velocity correction to the delta_T maps
min_gradient_component = 1.0;

for (i=0; i<HII_DIM; i++){
for (j=0; j<HII_DIM; j++){
if(USE_TS_IN_21CM) {
for (i=0; i<HII_DIM; i++){
for (j=0; j<HII_DIM; j++){
for (k=0; k<HII_DIM; k++){

gradient_component = fabs(v[HII_R_FFT_INDEX(i,j,k)]/H + 1.0);

// Calculate the brightness temperature, using the optical depth
if(gradient_component < FRACT_FLOAT_ERR) {
// Gradient component goes to zero, optical depth diverges. But, since we take exp(-tau), this goes to zero and (1 - exp(-tau)) goes to unity.
// Again, factors of 1000. are conversions from K to mK
delta_T[HII_R_INDEX(i,j,k)] = 1000.*(Ts[HII_R_INDEX(i,j,k)] - T_rad)/(1. + REDSHIFT);
}
else {
delta_T[HII_R_INDEX(i,j,k)] = (1. - exp(- delta_T[HII_R_INDEX(i,j,k)]/gradient_component ))*1000.*(Ts[HII_R_INDEX(i,j,k)] - T_rad)/(1. + REDSHIFT);
}
}
}
}
}
else {
// now add the velocity correction to the delta_T maps
max_v_deriv = fabs(MAX_DVDR*H);
for (i=0; i<HII_DIM; i++){
for (j=0; j<HII_DIM; j++){
for (k=0; k<HII_DIM; k++){

gradient_component = fabs(v[HII_R_FFT_INDEX(i,j,k)]/H + 1.0);

// Calculate the brightness temperature, using the optical depth
if(gradient_component < FRACT_FLOAT_ERR) {
// Gradient component goes to zero, optical depth diverges. But, since we take exp(-tau), this goes to zero and (1 - exp(-tau)) goes to unity.
// Again, factors of 1000. are conversions from K to mK
delta_T[HII_R_INDEX(i,j,k)] = 1000.*(Ts[HII_R_INDEX(i,j,k)] - T_rad)/(1. + REDSHIFT);
}
else {
delta_T[HII_R_INDEX(i,j,k)] = (1. - exp(- delta_T[HII_R_INDEX(i,j,k)]/gradient_component ))*1000.*(Ts[HII_R_INDEX(i,j,k)] - T_rad)/(1. + REDSHIFT);

dvdx = v[HII_R_FFT_INDEX(i,j,k)];

// set maximum allowed gradient for this linear approximation
if (fabs(dvdx) > max_v_deriv){
if (dvdx < 0) dvdx = -max_v_deriv;
else dvdx = max_v_deriv;
nonlin_ct++;
}

delta_T[HII_R_INDEX(i,j,k)] /= (dvdx/H + 1.0);

}
}
}

}

// normalised units of cell length. 0 equals beginning of cell, 1 equals end of cell
Expand Down
4 changes: 2 additions & 2 deletions Programs/find_HII_bubbles.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ int main(int argc, char ** argv){
if (INHOMO_RECO) { init_MHR();}
if (HALO_MASS_DEPENDENT_IONIZING_EFFICIENCY) {
init_21cmMC_arrays();
Mlim_Fstar = Mass_limit_bisection(M_TURN/50., 1e16, ALPHA_STAR, F_STAR10);
Mlim_Fesc = Mass_limit_bisection(M_TURN/50., 1e16, ALPHA_ESC, F_ESC10);
Mlim_Fstar = Mass_limit(ALPHA_STAR, F_STAR10);
Mlim_Fesc = Mass_limit(ALPHA_ESC, F_ESC10);
ION_EFF_FACTOR = N_GAMMA_UV * F_STAR10 * F_ESC10;
}
else
Expand Down
6 changes: 3 additions & 3 deletions Programs/heating_helper_progs.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ double xion_RECFAST(float z, int flag);
double T_RECFAST(float z, int flag);

/* Main driver for evolution */
void evolveInt(float zp, float curr_delNL0[], double freq_int_heat[],
void evolveInt(float zp, int arr_num, float curr_delNL0[], double freq_int_heat[],
double freq_int_ion[], double freq_int_lya[],
int COMPUTE_Ts, double y[], double deriv[]);
//float Mturn, float ALPHA_STAR, float F_STAR10, float T_AST);
Expand Down Expand Up @@ -293,7 +293,7 @@ double spectral_emissivity(double nu_norm, int flag)
************************** IGM Evolution ***************************
This function creates the d/dz' integrands
*********************************************************************/
void evolveInt(float zp, float curr_delNL0[], double freq_int_heat[],
void evolveInt(float zp, int arr_num, float curr_delNL0[], double freq_int_heat[],
double freq_int_ion[], double freq_int_lya[],
int COMPUTE_Ts, double y[], double deriv[]){
double dfdzp, dadia_dzp, dcomp_dzp, dxheat_dt, ddz, dxion_source_dt, dxion_sink_dt;
Expand Down Expand Up @@ -345,7 +345,7 @@ void evolveInt(float zp, float curr_delNL0[], double freq_int_heat[],
// Usage of 0.99*Deltac arises due to the fact that close to the critical density, the collapsed fraction becomes a little unstable
// However, such densities should always be collapsed, so just set f_coll to unity.
// Additionally, the fraction of points in this regime relative to the entire simulation volume is extremely small.
splint(Overdense_high_table-1,SFRD_z_high_table[zpp_ct]-1,second_derivs_Nion_zpp[zpp_ct]-1,NSFR_high,curr_delNL0[zpp_ct]*growth_zpp,&(fcoll));
splint(Overdense_high_table-1,SFRD_z_high_table[arr_num+zpp_ct]-1,second_derivs_Nion_zpp[zpp_ct]-1,NSFR_high,curr_delNL0[zpp_ct]*growth_zpp,&(fcoll));
}
else {
fcoll = 1.;
Expand Down

0 comments on commit 94419d1

Please sign in to comment.