Example #1
0
double cosmology::pe_fraction(double mvir0,double z0,double z1,double z2){
    if(!bool_pe_rho_rdelta_phys_Zhao || mvir0!=Mvir_for_pe || z0!=z_for_pe){
        std::cout<<"# Initializing physical density profile for "<<mvir0<<" at z="<<z0<<std::endl<<std::endl;
        init_pe_rho_rdelta_phys_Zhao(mvir0,z0);
    }
    if(z0>z1 || z0>z2){
        std::cout<<"# z0 should be smaller than z1 and z2\n";
        return 0;
    }
    if(z2<z1){
        std::cout<<"# z1 should be smaller than z2\n";
        return 0;
    }
    /// Calculate the total mass evolution
    double Mvir1=gsl_spline_eval(mah_Zhao_spline,z1,mah_Zhao_acc);
    double Mvir2=gsl_spline_eval(mah_Zhao_spline,z2,mah_Zhao_acc);
    //mofz=(Mvir1+Mvir2)/2.;

    double Rvir1=rvir_from_mvir(Mvir1,z1);
    Rvir1=Rvir1/(1+z1);
    double Rvir2=rvir_from_mvir(Mvir2,z2);
    Rvir2=Rvir2/(1+z2);

    /// Calculate the pseudo-evolution component
    double Mpe=gsl_spline_eval_integ(pe_rho_rdelta_phys_Zhao_spline,Rvir2,Rvir1,pe_rho_rdelta_phys_Zhao_acc);
    //std::cout<<"DEBUG: "<<Mpe<<" "<<Mvir2-Mvir1<<std::endl;

    //printf("DEBUG : %e %e %e %e \n",Mvir1,Rvir1,Mvir2,Rvir2);
    //exit(101);

    return Mpe/(Mvir1-Mvir2);
}
Example #2
0
static VALUE rb_gsl_spline_eval_integ(VALUE obj, VALUE aa, VALUE bb)
{
  rb_gsl_spline *sp = NULL;
  gsl_spline *s = NULL;
  gsl_interp_accel *acc = NULL;
  double a, b;
  Need_Float(aa);
  Need_Float(bb);
  Data_Get_Struct(obj, rb_gsl_spline, sp);
  s = sp->s;
  acc = sp->a;
  a = NUM2DBL(aa);
  b = NUM2DBL(bb);
  return rb_float_new(gsl_spline_eval_integ(s, a, b, acc));
}
Example #3
0
double cosmology::dM4rs_dMphys(double mvir0,double z0,double z1,double z2){
    if(!bool_pe_rho_rdelta_phys_Zhao || mvir0!=Mvir_for_pe || z0!=z_for_pe){
        std::cout<<"# Initializing physical density profile for "<<mvir0<<" at z="<<z0<<std::endl<<std::endl;
        init_pe_rho_rdelta_phys_Zhao(mvir0,z0);
    }
    if(z0>z1 || z0>z2){
        std::cout<<"# z0 should be smaller than z1 and z2\n";
        return 0;
    }
    if(z2<z1){
        std::cout<<"# z1 should be smaller than z2\n";
        return 0;
    }
    /// Calculate the total mass evolution
    double Mvir1=gsl_spline_eval(mah_Zhao_spline,z1,mah_Zhao_acc);
    double Mvir2=gsl_spline_eval(mah_Zhao_spline,z2,mah_Zhao_acc);
    //mofz=(Mvir1+Mvir2)/2.;

    double Rvir1=rvir_from_mvir(Mvir1,z1);
    Rvir1=Rvir1/(1+z1);
    double Rvir2=rvir_from_mvir(Mvir2,z2);
    Rvir2=Rvir2/(1+z2);

    /// Calculate the pseudo-evolution component
    double Mpe=gsl_spline_eval_integ(pe_rho_rdelta_phys_Zhao_spline,Rvir2,Rvir1,pe_rho_rdelta_phys_Zhao_acc);
    //std::cout<<"DEBUG: "<<Mpe<<" "<<Mvir2-Mvir1<<std::endl;
    
    double dMphys=Mvir1-Mvir2-Mpe;

    // First calculate concentration of these halos
    double conc1=conc(Mvir1,z1);
    double conc2=conc(Mvir2,z2);

    double M4rs1=getM4rs(Mvir1,conc1);
    double M4rs2=getM4rs(Mvir2,conc2);

    double dM4rs=(M4rs1-M4rs2);
    //fprintf(stderr,"# Mvir1:%e Mvir2:%e Mpe:%e dMphys:%e M4rs1:%e M4rs2:%e dM4rs:%e\n",Mvir1,Mvir2,Mpe,dMphys,M4rs1,M4rs2,dM4rs);

    if(dM4rs<0)
        return -1.0;
    else
        return dM4rs/dMphys;
}
Example #4
0
/* \fcnfh
 Computes optical depth at a given impact parameter, note that b needs
 to be given in units of 'rad' and the result needs to be multiplied by
 the units 'rad' to be real. 
 This uses a bent path ray solution.

 @returns $\frac{tau}{units_{rad}}$ returns optical depth divided by units
                                    of 'rad'
*/
static PREC_RES
totaltau2(PREC_RES b,		/* differential impact parameter with
				   respect to maximum value */
	  PREC_RES *rad,	/* radius array */
	  PREC_RES *refr,	/* refractivity index */
	  PREC_RES *ex,		/* extinction[rad] */
	  long nrad)		/* number of radii elements */
{
  PREC_RES dt[nrad];
  PREC_RES r0a=b;
  PREC_RES r0=0;
  int i;
  const int maxiterations=50;
  int rs;

  transiterror(TERR_CRITICAL|TERR_ALLOWCONT,
	       "Tau 2??? I'm afraid  that this has not been"
	       " successfully tested yet. I'll continue but"
	       " be critical of the result\n");

  //Look for closest approach radius
  i=0;
  while(1){
    r0=b/lineinterp(r0a,rad,refr,nrad);
    if(r0==r0a)
      break;
    if(i++>maxiterations)
      transiterror(TERR_CRITICAL,
		   "Maximum iterations(%i) reached while looking for\n"
		   "r0. Convergence not reached (%.6g!=%.6g)\n"
		   ,maxiterations,r0,r0a);
    r0a=r0;
  }

  //get bin value 'rs' such that r0 is between rad[rs-1] inclusive
  //and rad[rs] exclusive.
  //If we are looking at the outmost layer, then return
  if((rs=binsearch(rad,0,nrad-1,r0))==-5)
    return 0;
  //If some other error occurred
  else if(rs<0)
    transiterror(TERR_CRITICAL,
		 "Closest approach value(%g) is outside sampled radius\n"
		 "range(%g - %g)\n"
		 ,r0,rad[0],rad[nrad-1]);
  //advance the index to point as desired. Now nrad-rs indicates the
  //number of points available for integration.
  rs++;

  //A fraction 'analiticfrac' of the integration near the closest
  //appraoach is calcualated analitically, otherwise, I get a division
  //by zero. In formula\par
  //\[
  //\tau_{\wn}(\rho)=
  //\underbrace{
  //\frac{2\extc_{\wn}\rho}{n}\left(
  //                   \sqrt{\left(\frac{nr_1}{\rho}\right)^2-1}
  //                  -\sqrt{\left(\frac{nr_0}{\rho}\right)^2-1}\right) 
  //}_{\mathrm{analitic}} +
  //\underbrace{
  //2\int_{r_1=r_0+\delta r}^{\infty}
  //\frac{\extc_{\wn}~n~r}{\sqrt{n^2r^2-\rho^2}}\dd r
  //}_{\mathrm{numerical}}
  //\]\par
  //First for the analitical part of the integral
  PREC_RES res;
  if(ex[rs-1]==ex[rs])
    res= ex[rs] * r0 * ( sqrt( rad[rs] * rad[rs] / r0 / r0 - 1) );
  else{
    PREC_RES alpha = ( ex[rs] - ex[rs-1] ) / ( rad[rs] - rad[rs-1] );
    PREC_RES rm    = rad[rs];
    if(alpha<0)
      res= - alpha * (rm * sqrt( rm * rm - r0 * r0) - r0 * r0 * 
		      log( sqrt( rm * rm / r0 / r0 - 1) + rm / r0 ) )
	/ 2.0;
    else
      res=   alpha * (rm * sqrt( rm * rm - r0 * r0) + r0 * r0 * 
		      log( sqrt( rm * rm / r0 / r0 - 1) + rm / r0 ) )
	/ 2.0;
  }

  //And now for the numerical integration. Set the variables
  for(i=rs;i<nrad;i++){
    r0a=b/refr[i]/rad[i];
    transitASSERT(r0a>1,
		  "Oops! condition could not be asserted, b/(nr)=%g > 1\n"
		  ,r0a);

    dt[i]=ex[i]/sqrt(1-r0a*r0a);
  }

  //Integrate!\par
  //Use spline if GSL is available along with at least 3 points
#ifdef _USE_GSL
  if(nrad-rs>2){
    gsl_interp_accel *acc = gsl_interp_accel_alloc ();
    gsl_spline *spl=gsl_spline_alloc(gsl_interp_cspline,nrad-rs);
    gsl_spline_init(spl,rad+rs,dt+rs,nrad-rs);
    res+=gsl_spline_eval_integ(spl,rad[rs],rad[nrad-1],acc);
    gsl_spline_free(spl);
    gsl_interp_accel_free (acc);
  }
  //Only integrate Trapezium if there are only two points available.
  else
#endif /* _USE_GSL */
  //Integrate Simpson-Trapezium if enough(w/o GSL) or not enough(w/ GSL)
  //elements. 
  if(nrad-rs>1)
    res+=integ_trasim(rad[1]-rad[0],dt+rs,nrad-rs);

  return 2*(res);
}
Example #5
0
/* Returns the integral of the spline stored in spl, between a and b */
double FC_FUNC_(oct_spline_eval_integ, OCT_SPLINE_EVAL_INTEG)
     (const void **spl, const double *a, const double *b, void **acc)
{
  /* the GSL headers specify double a, double b */
  return gsl_spline_eval_integ((gsl_spline *)(*spl), *a, *b, (gsl_interp_accel *)(* acc));
}
Example #6
0
double Interpolate::integ(double a, double b) {
	return gsl_spline_eval_integ (_spline, a, b, _acc);
}