Ejemplo n.º 1
0
double dtau_e_dz(double z, void *params){
  float xH, xi;
  int i=1;
  tau_e_params p = *(tau_e_params *)params;

  if ((p.len == 0) || !(p.z))
    return (1+z)*(1+z)*drdz(z);
  else{
    // find where we are in the redshift array
    if (p.z[0]>z) // ionization fraction is 1 prior to start of array
      return (1+z)*(1+z)*drdz(z);
    while ( (i < p.len) && (p.z[i] < z) ) {i++;}
    if (i == p.len)
      return 0;

    // linearly interpolate in redshift
    xH = p.xH[i-1] + (p.xH[i] - p.xH[i-1])/(p.z[i] - p.z[i-1]) * (z - p.z[i-1]);
    /*
    fprintf(stderr, "in taue: Interpolating between xH(%f)=%f and xH(%f)=%f to obtain xH(%f)=%f\n",
    p.z[i-1], p.xH[i-1], p.z[i], p.xH[i], z, xH);
    */
    xi = 1.0-xH;
    if (xi<0){
      fprintf(stderr, "in taue: funny buisness xi=%e, changing to 0\n", xi);
      xi=0;
    }
    if (xi>1){
      fprintf(stderr, "in taue: funny buisness xi=%e, changing to 1\n", xi);
      xi=1;
    }
      
    return xi*(1+z)*(1+z)*drdz(z);
  }
}
Ejemplo n.º 2
0
int main(int argc, char * argv[]) {

  int i,nz,ind;
  double z,dz=0.01,zv[1000],xH[1000];
  double nH0,nHe0,ne0,tau,tau2,ddz;
  FILE *fid;
  char fname[300];

  /* Check for correct number of parameters*/
  if (argc != 2) {
    printf("Usage : opdepth base_dir (for simulation)\n");
    exit(0);
  }

  get_Simfast21_params(argv[1]);

  sprintf(fname,"%s/Output_text_files/zsim.txt",argv[1]);
  if((fid = fopen(fname,"r"))==NULL) {
    printf("Error opening file:%s\n",fname);
    exit(1);
  }
  i=0;
  while(fscanf(fid,"%lf",&(zv[i]))==1) i++;
  nz=i;
  printf("Number of lines: %d\n",nz);
  fclose(fid);    
  sprintf(fname, "%s/Output_text_files/x_HI_eff%.2lf_N%ld_L%.0f.dat",argv[1],global_eff,global_N_smooth,global_L/global_hubble);
  if((fid = fopen(fname,"r"))==NULL) {
    printf("Error opening file:%s\n",fname);
    exit(1);
  }
  i=0;
  while(fscanf(fid,"%lf",&(xH[i]))==1) i++;
  fclose(fid);
  if(i!=nz) {printf("Error!\n");exit(1);}
  nH0=(1.-YHe)*(global_rho_b*Msun/pow(Mpc2m*100./global_hubble,3))/mH; /* cm^-3 */
  nHe0=(YHe)*(global_rho_b*Msun/pow(Mpc2m*100./global_hubble,3))/mHe;  /* cm^-3 */
  ne0=nH0+nHe0;
  tau=0.;
  for(z=0.;z<zv[nz-1];z+=dz) {
    tau+=(1.+z)*(1.+z)*drdz(z);
  }
  tau=tau*dz*ne0*sigt*Mpc2m/global_hubble*100.;
  printf("Full ionization part: %E\n",tau);
  ddz=(zv[0]-zv[nz-1])/(nz-1);
  tau2=0.;
  while(z<=zv[0]) {
    ind=(int)round((z-zv[nz-1])/ddz);
    if(ind>nz-1 || ind <0) printf("Error - ind: %d\n",ind);
    ind=nz-1-ind;
    tau2+=(1.+z)*(1.+z)*drdz(z)*(1.-xH[ind]);
    z+=dz;
  }
  tau2=tau2*dz*ne0*sigt*Mpc2m/global_hubble*100.;
  printf("xHII ionization part: %E\n",tau2);
  printf("Total: %E\n",tau+tau2);
  
  exit(0);

}
Ejemplo n.º 3
0
/* Return the comoving distance (in cm) traveled by photon (i.e. length of a null geodesic) from zsource to z */
double dcom_dz(double z, void *params){
  return drdz(z);
}