示例#1
0
文件: driftfac.c 项目: Ingwar/amuse
/*! This function computes look-up tables for factors needed in
 *  cosmological integrations. The (simple) integrations are carried out
 *  with the GSL library.  Separate factors are computed for the "drift",
 *  and the gravitational and hydrodynamical "kicks".  The lookup-table is
 *  used for reasons of speed.
 */
void init_drift_table(void)
{
#define WORKSIZE 100000
  int i;
  double result, abserr;
  gsl_function F;
  gsl_integration_workspace *workspace;

  logTimeBegin = log(All.TimeBegin);
  logTimeMax = log(All.TimeMax);

  workspace = gsl_integration_workspace_alloc(WORKSIZE);

  for(i = 0; i < DRIFT_TABLE_LENGTH; i++)
    {
      F.function = &drift_integ;
      gsl_integration_qag(&F, exp(logTimeBegin), exp(logTimeBegin + ((logTimeMax - logTimeBegin) / DRIFT_TABLE_LENGTH) * (i + 1)), 0,
			  1.0e-8, WORKSIZE, GSL_INTEG_GAUSS41, workspace, &result, &abserr);
      DriftTable[i] = result;


      F.function = &gravkick_integ;
      gsl_integration_qag(&F, exp(logTimeBegin), exp(logTimeBegin + ((logTimeMax - logTimeBegin) / DRIFT_TABLE_LENGTH) * (i + 1)), 0,
			  1.0e-8, WORKSIZE, GSL_INTEG_GAUSS41, workspace, &result, &abserr);
      GravKickTable[i] = result;


      F.function = &hydrokick_integ;
      gsl_integration_qag(&F, exp(logTimeBegin), exp(logTimeBegin + ((logTimeMax - logTimeBegin) / DRIFT_TABLE_LENGTH) * (i + 1)), 0,
			  1.0e-8, WORKSIZE, GSL_INTEG_GAUSS41, workspace, &result, &abserr);
      HydroKickTable[i] = result;
    }

  gsl_integration_workspace_free(workspace);
}
示例#2
0
/*gsl_integrate: wrapper for the GSL QAG integration routine
 *@param min: Input, lower bound of integral
 *@param max: Input, upper bound of integral
 *@param n: Input, harmonic number and index of sum over n
 *@param nu: Input, frequency of emission/absorption
 *@returns: Output, result of either gamma integral or n integral
 */
double gsl_integrate(double min, double max, double n, double nu)
{
  double nu_c = (electron_charge * B_field)
               /(2. * M_PI * mass_electron * speed_light);
  if (nu/nu_c > 1.e6) {
    gsl_set_error_handler_off();
  }
  gsl_integration_workspace * w = gsl_integration_workspace_alloc (5000);
  double result, error;
  gsl_function F;
  if (n < 0) { //do n integration
    F.function = &gamma_integration_result;
    F.params = &nu;
    gsl_integration_qag(&F, min, max, 0., 1.e-3, 200,
                         3,  w, &result, &error);
  }
  else {  //do gamma integration
  struct parameters n_and_nu;
  n_and_nu.n = n;
  n_and_nu.nu = nu;
  F.function = &gamma_integrand;
  F.params = &n_and_nu;
  gsl_integration_qag(&F, min, max, 0., 1.e-3, 200,
                       3,  w, &result, &error);
  }

  gsl_integration_workspace_free (w);
  return result;
}
示例#3
0
static double int_aux(int index, double kx, double kr, double x0, double r0, int which_int)
{
  /*variables*/
  double result, error;
  double xinf = 100.0/r0;
  struct parameters params;

  /*pass the given parameters to program*/
  const size_t wrk_size = 5000;
  /* I believe that 1e-6 is over-killing, a substantial gain in time
     is obtained by setting this threshold to 1e-3 */
  /* const double epsilon_abs = 1e-6; */
  /* const double epsilon_rel = 1e-6; */
  const double epsilon_abs = 1e-3;
  const double epsilon_rel = 1e-3;

  /*creating the workspace*/
  gsl_integration_workspace * ws = gsl_integration_workspace_alloc (wrk_size);

  /*create the function*/
  gsl_function F;

  assert(which_int == PFC_F_0 || which_int == PFC_F_KR || which_int == PFC_F_KX);

  params.kx = kx;
  params.kr = kr;
  params.x0 = x0;
  params.r0 = r0;
  params.index = index;

  F.params = &params;
      
  /*select the integration method*/
  switch(which_int){
  case PFC_F_0:
    F.function = &f;
    gsl_integration_qag(&F, -xinf, xinf, epsilon_abs, epsilon_rel, 
			wrk_size, 3, ws, &result, &error);
    break;
  case PFC_F_KX:
    F.function = &f_kx_zero;
    gsl_integration_qag (&F, 0.0, r0, epsilon_abs, epsilon_rel, 
			 wrk_size, 3, ws, &result, &error);
    break;
  case PFC_F_KR:
    F.function = &f_kr_zero;
    gsl_integration_qag (&F, 0.0, x0, epsilon_abs, epsilon_rel, 
			 wrk_size, 3, ws, &result, &error);
    break;
  }

  /*free the integration workspace*/
  gsl_integration_workspace_free (ws);
  
  /*return*/
  return result;
}
static gdouble
_nc_cluster_mass_benson_intp (NcClusterMass *clusterm, NcHICosmo *model, gdouble lnM, gdouble z)
{
  integrand_data data;
  NcClusterMassBenson *msz = NC_CLUSTER_MASS_BENSON (clusterm);
  gdouble P, err;
  const gdouble E0 = nc_hicosmo_E (model, msz->z0); 
  const gdouble E = nc_hicosmo_E (model, z);
  gsl_function F;
  gsl_integration_workspace **w = ncm_integral_get_workspace ();

  data.msz = msz;
  data.model = model;
  data.lnM = lnM;
  data.z = z;

  data.lnA = log (A_SZ);
  data.lnM0 = log (msz->M0);
  data.lnE_E0 = log (E / E0);
  data.mu = B_SZ * (lnM - data.lnM0) + C_SZ * data.lnE_E0 + data.lnA;
  data.D2_2 = 2.0 * D_SZ * D_SZ;

  F.function = &_nc_cluster_mass_benson_significance_m_intp_integrand;
  F.params = &data;
  
  {
    gdouble Pi, a, b;
//    a = 0.25;
//    b = 1.0;
    a = 0.0;
    b = 1.0;
    gsl_integration_qag (&F, a, b, 0.0, NCM_DEFAULT_PRECISION, NCM_INTEGRAL_PARTITION, 6, *w, &Pi, &err);
    P = Pi;
//    b = 2.0;
    b = 1.0;
//printf ("int_p[0,1] % 8.5g % 8.5g : % 8.5g % 8.5g\n", exp (lnM), z, P, data.mu);
    do {
      a = b;
      b += msz->signif_obs_max;
      gsl_integration_qag (&F, a, b, P * NCM_DEFAULT_PRECISION, NCM_DEFAULT_PRECISION, NCM_INTEGRAL_PARTITION, 6, *w, &Pi, &err); 
      P += Pi;
    } while (fabs(Pi/P) > NCM_DEFAULT_PRECISION);
  }

  ncm_memory_pool_return (w);

//printf ("int_p[2,-] % 8.5g % 8.5g : % 8.5g % 8.5g\n", exp (lnM), z, P, data.mu);

  
  return P;
}
示例#5
0
int
qagiu (gsl_function * f,
                       double a,
                       double epsabs, double epsrel, size_t limit,
                       gsl_integration_workspace * workspace,
                       double *result, double *abserr)
{
  int status;

  gsl_function f_transform;
  struct iu_params transform_params  ;

  transform_params.a = a ;
  transform_params.f = f ;

  f_transform.function = &iu_transform;
  f_transform.params = &transform_params;

  status = gsl_integration_qag (&f_transform, 0.0, 1.0, 
                                epsabs, epsrel, limit, 3,
                                workspace,
                                result, abserr);

  return status;
}
示例#6
0
double V_1(double x, double y)
{
    double * dargs = ml_alloc<double> (10);
    void * arg_ptr = (void *)dargs;
    
    dargs[0] = x;
    dargs[1] = y;
    
    double epsabs=1E-6;
    double epsrel=1E-10;
    
    double result,real_abserr,imag_result,imag_abserr;
    static gsl_integration_workspace * workspace = gsl_integration_workspace_alloc (1000000);
    
    gsl_function F;
    F.function = integrand;
    F.params = arg_ptr;
    
    gsl_integration_qag (
        &F,
        0,
        1,
        epsabs,
        epsrel,
        200000,
        6,
        workspace,
        &result,
        &real_abserr );
    
    return result;
}
示例#7
0
Real 
GreensFunction3DRadInf::Rn(unsigned int n, Real r, Real t,
                            gsl_integration_workspace* workspace,
                            Real tol) const
{
    Real integral;
    Real error;

    p_corr_R_params params = { this, n, r, t };
    gsl_function F = 
        {
            reinterpret_cast<double (*)(double, void*)>(&p_corr_R_F),
            &params
        };

    const Real umax(sqrt(40.0 / (this->getD() * t))); 

    gsl_error_handler_t* old_handler = gsl_set_error_handler(&my_gsl_error_handler);
    // gsl_error_handler_t* old_handler = gsl_set_error_handler_off();
    gsl_integration_qag(&F, 0.0,
                        umax,
                        tol,
                        THETA_TOLERANCE,
                        2000, GSL_INTEG_GAUSS61,
                        workspace, &integral, &error);
    gsl_set_error_handler(old_handler);

    return integral;
}
示例#8
0
int compute_itegral(const gsl_vector *k, const void * p, gsl_vector *out){
    //delta=phase_f(k)+phc_f(k); omega= 2.0*k
    struct fit_params * fp = (struct fit_params *)p;
    double L=10.0, result, error;

    gsl_function F;
    struct student_params params;
    params.mu=fp->mu; params.sig=fp->sig; params.skew=fp->skew; params.nu=fp->nu;
    F.function = &itegral_student;
    F.params = &params;
    if ( params.nu < -1. )
    {
        gsl_vector_set_zero(out);
        return GSL_SUCCESS;
    } 
    gsl_integration_workspace * w         = gsl_integration_workspace_alloc (10000);
    for (int i=0; i< k->size; i++){
        double kv=gsl_vector_get(k, i);
        params.delta= gsl_spline_eval(splines.pha_spline, kv, splines.acc) + \
                       gsl_spline_eval(splines.phc_spline, kv, splines.acc);
        params.omega=2.*kv;
        params.lam  = gsl_spline_eval(splines.lam_spline, kv, splines.acc);
        //printf("%12.5f %12.5f %12.5f %12.5f %12.5f %12.5f\n",  kv, params.delta, params.lam, params.mu, params.sig, params.skew );
        gsl_integration_qag(&F, 0.1, L, 0., 1e-8, 1000, GSL_INTEG_GAUSS51, w, &result, &error); 
        //gsl_integration_qawo (&F, 0., 0., 1e-7, 100, w, int_table, &result, &error);
        //amp=N*S02*mag_f(k_var)*np.power(k_f(k_var), kweight-1.0)*tmp
        result*=double(N)*(-1.*fp->S02)*gsl_spline_eval(splines.mag_spline, kv, splines.acc)/kv;
        gsl_vector_set(out, i, result);  
    }
    gsl_integration_workspace_free (w);
    return GSL_SUCCESS;}
//------------------------------------------------------------------------------
int IntegratorAdaptive::integrate(const Function1D f, double a, double b, double& result, double& error)
{
   gsl_function integrand;
   GSLFunction tmp = f.getGSLFunction();
   integrand.function = tmp.f;
   integrand.params = tmp.p;
   try {
      gsl_integration_qag(&integrand, a, b, _absPrecision, _relPrecision,
                          _maxIterations, _rule, _workspace, &result, &error);
   } catch (const runtime_error& err) {
      switch (err.gsl_errno()) {
         case GSL_EMAXITER:
            Integration::max_iterations::issue(_maxIterations);
            break;
         case GSL_EROUND:
            Integration::round_off::issue();
            break;
         case GSL_ESING:
            Integration::bad_integrand::issue();
            break;
         default: throw err;
      }
      Integration::failed_tolerance::issue(result, error, std::max(_absPrecision, _relPrecision * std::abs(result)));
      return err.gsl_errno();
   }
   return 0;
}
示例#10
0
gdouble
nc_ca_mean_bias_denominator (NcClusterAbundance *cad, NcHICosmo *cosmo, gdouble lnM, gdouble z)
{
  observables_integrand_data obs_data;
  gdouble mean_bias_denominator;
  gsl_function F;
  obs_data.cad = cad;
  obs_data.cosmo = cosmo;

  F.function = &_nc_ca_mean_bias_denominator_integrand;
  F.params = &obs_data;

  {
    gdouble res, err;
    gdouble lnMf = cad->lnMf;
    obs_data.z = z;
    obs_data.lnM = lnM;
    {
      gsl_integration_workspace **w = ncm_integral_get_workspace ();
      gsl_integration_qag (&F, lnM, lnMf, 0.0, NCM_DEFAULT_PRECISION, NCM_INTEGRAL_PARTITION, _NC_CLUSTER_ABUNDANCE_DEFAULT_INT_KEY, *w, &res, &err);
      ncm_memory_pool_return (w);
    }
    mean_bias_denominator= res;
  }

  return mean_bias_denominator;
}
示例#11
0
/**
 * nc_cluster_abundance_z_p_d2n:
 * @cad: a #NcClusterAbundance
 * @cosmo: a #NcHICosmo
 * @clusterz: a #NcClusterRedshift
 * @clusterm: a #NcClusterMass
 * @lnM: the logarithm base e of the mass (gdouble)
 * @z_obs: (array) (element-type gdouble): observed redshift
 * @z_obs_params: (array) (element-type gdouble): FIXME
 *
 * This function computes $ \int_{z_{phot} - 10\sigma_{phot}}^{z_{phot} + 10\sigma_{phot}} dz \,
 * \frac{d^2N}{dzdlnM} * P(z^{photo}|z) $. The integral limits were determined requiring a precision
 * to five decimal places.
 *
 * Returns: a gdouble which corresponds to $ \int_{z_{phot} - 10\sigma_{phot}}^{z_{phot} + 10\sigma_{phot}} dz \,
 * \frac{d^2N}{dzdlnM} * P(z^{photo}|z) $.
 */
gdouble
nc_cluster_abundance_z_p_d2n (NcClusterAbundance *cad, NcHICosmo *cosmo, NcClusterRedshift *clusterz, NcClusterMass *clusterm, gdouble lnM, gdouble *z_obs, gdouble *z_obs_params)
{
  observables_integrand_data obs_data;
  gdouble d2N, zl, zu, err;
  gsl_function F;
  gsl_integration_workspace **w = ncm_integral_get_workspace ();

  obs_data.cad            = cad;
  obs_data.cosmo          = cosmo;
  obs_data.clusterz       = clusterz;
  obs_data.clusterm       = clusterm;
  obs_data.lnM            = lnM;
  obs_data.z_obs          = z_obs;
  obs_data.z_obs_params   = z_obs_params;

  F.function = &_nc_cluster_abundance_z_p_d2n_integrand;
  F.params = &obs_data;

  nc_cluster_redshift_p_limits (clusterz, z_obs, z_obs_params, &zl, &zu);

  gsl_integration_qag (&F, zl, zu, 0.0, NCM_DEFAULT_PRECISION, NCM_INTEGRAL_PARTITION, _NC_CLUSTER_ABUNDANCE_DEFAULT_INT_KEY, *w, &d2N, &err);

  ncm_memory_pool_return (w);

  return d2N;
}
    // ========================================================================
    // simple adaptive integration
    // ========================================================================
    double NumericalDefiniteIntegral::QAG ( _Function* F ) const
    {
      if( 0 == F ) { Exception("QAG::invalid function") ; }

      // allocate workspace
      if( 0 == ws () ) { allocate () ; }

      // integration limits
      const double low  = std::min ( m_a , m_b ) ;
      const double high = std::max ( m_a , m_b ) ;

      int ierror =
        gsl_integration_qag ( F->fn                    ,
                              low       ,         high ,
                              m_epsabs  ,     m_epsrel ,
                              size   () , (int) rule() , ws ()->ws ,
                              &m_result ,     &m_error             );

      if( ierror ) { gsl_error( "NumericalDefiniteIntegral::QAG " ,
                                __FILE__ , __LINE__ , ierror ) ; }

      // sign
      if ( m_a > m_b ) { m_result *= -1 ; }

      return m_result ;
    }
示例#13
0
文件: mixing.cpp 项目: Ingwar/amuse
void smoothing_integrate(smoothing_params &params, int n) {
  int n_int = 2*n;

  params.acc_y = gsl_interp_accel_alloc();
  params.int_y = gsl_interp_alloc(gsl_interp_linear, n);
  params.n     = n;
  gsl_interp_init(params.int_y, params.arr_x, params.arr_y, n);

  /* setup integration workspace */

  gsl_integration_workspace *w = gsl_integration_workspace_alloc(n_int);
  gsl_function F; 
  F.function = &smoothing_integrand;
  F.params   = &params;
  
  double eps_abs = 0.0, eps_rel = 0.01;
  double result, error;
  gsl_set_error_handler_off();
 
  for (int i = 0; i < n; i++) {
    params.x = params.arr_x[i];
    params.h = 0.1; //0.1*params.x + 1.0e-4;

    gsl_integration_qag(&F, 
			params.x - 2*params.h, params.x + 2*params.h,
			eps_abs, eps_rel,
			n_int, 1,
			w, &result, &error);
    params.smoothed_y[i] = result;
  }
  
  gsl_integration_workspace_free(w);
  gsl_interp_accel_free(params.acc_y);
  gsl_interp_free(params.int_y);
}
示例#14
0
gdouble
nc_ca_mean_bias_Mobs_denominator (NcClusterAbundance *cad, NcHICosmo *cosmo, gdouble lnMobs, gdouble z)
{
  observables_integrand_data obs_data;
  gdouble mean_bias_Mobs_denominator;
  gsl_function F;
  obs_data.cad = cad;
  obs_data.cosmo = cosmo;
  
  F.function = &_nc_ca_mean_bias_Mobs_denominator_integrand;
  F.params = &obs_data;

  {
    obs_data.z = z;
    obs_data.lnM = lnMobs;
    {
      gdouble res, err;
      gdouble lnMl = 0.0, lnMu = 0.0;
      //lnMl = GSL_MAX (lnMobs - 7.0 * obs_data.cad->lnM_sigma0, LNM_MIN);
      //lnMu = GSL_MIN (lnMobs + 7.0 * obs_data.cad->lnM_sigma0, 16.3 * M_LN10);
      //lnMl = lnMobs - 7.0 * obs_data.cad->lnM_sigma0;
      //lnMu = lnMobs + 7.0 * obs_data.cad->lnM_sigma0;
      g_assert_not_reached ();
      {
        gsl_integration_workspace **w = ncm_integral_get_workspace ();

        gsl_integration_qag (&F, lnMl, lnMu, 0.0, NCM_DEFAULT_PRECISION, NCM_INTEGRAL_PARTITION, _NC_CLUSTER_ABUNDANCE_DEFAULT_INT_KEY, *w, &res, &err);
        ncm_memory_pool_return (w);
      }
      mean_bias_Mobs_denominator = res;
    }
  }

  return mean_bias_Mobs_denominator;
}
示例#15
0
static void comp_lens_power_spectrum(lensPowerSpectra lps)
{
#define WORKSPACE_NUM 100000
#define ABSERR 1e-12
#define RELERR 1e-12
#define TABLE_LENGTH 1000
  
  gsl_integration_workspace *workspace;
  gsl_function F;
  double result,abserr;
  double logltab[TABLE_LENGTH];
  double logpkltab[TABLE_LENGTH];
  double chimax;
  int i;
  
  //fill in bin information
  chiLim = lps->chiLim;
  if(lps->chis1 > lps->chis2)
    chimax = lps->chis1;
  else
    chimax = lps->chis2;
  
  fprintf(stderr,"doing lens pk - chiLim = %lf, chiMax = %lf\n",chiLim,chimax);
  
  //init
  workspace = gsl_integration_workspace_alloc((size_t) WORKSPACE_NUM);
  F.function = &lenspk_integrand;
  F.params = lps;
  
  //make table
  double lnlmin = log(wlData.lmin);
  double lnlmax = log(wlData.lmax);
  for(i=0;i<TABLE_LENGTH;++i)
    {
      logltab[i] = i*(lnlmax-lnlmin)/(TABLE_LENGTH-1) + lnlmin;
      
      lps->ell = exp(logltab[i]);
      gsl_integration_qag(&F,0.0,chimax,ABSERR,RELERR,(size_t) WORKSPACE_NUM,GSL_INTEG_GAUSS51,workspace,&result,&abserr);
      
      logpkltab[i] = log(result);
    }
  
  //free
  gsl_integration_workspace_free(workspace);
  
  //init splines and accels
  if(lps->spline != NULL)
    gsl_spline_free(lps->spline);
  lps->spline = gsl_spline_alloc(gsl_interp_akima,(size_t) (TABLE_LENGTH));
  gsl_spline_init(lps->spline,logltab,logpkltab,(size_t) (TABLE_LENGTH));
  if(lps->accel != NULL)
    gsl_interp_accel_reset(lps->accel);
  else
    lps->accel = gsl_interp_accel_alloc();
    
#undef TABLE_LENGTH
#undef ABSERR
#undef RELERR
#undef WORKSPACE_NUM
}
示例#16
0
// -----------------------------------------------------------------
// Returns ratio (Omega / Omega_*)^(2(alpha + 1))
double star(double delta, double epsilon, int order, double *c,
            double alpha) {

  double pow = alpha + 1.0;
  double intres, interr, ret, temp, seps = sqrt(epsilon);
  error2_pars_type error2_pars;
  error2_pars.epsilon = epsilon;
  error2_pars.order = order;
  error2_pars.c = c;
  error2_pars.alpha = alpha;

  gsl_function gsl_error2 = {&error2, &error2_pars};
  gsl_integration_workspace *gsl_ws_int
                            = gsl_integration_workspace_alloc(1000000);

  gsl_integration_qag(&gsl_error2, -seps, seps, 1.e-2, 0, 1000000,
                      GSL_INTEG_GAUSS15, gsl_ws_int, &intres, &interr);

  temp = gsl_sf_exp(pow * gsl_sf_log((1.0 - seps) / (1.0 + seps)) / 2.0);
  ret = temp + pow * intres;
  temp = gsl_sf_exp(gsl_sf_log(ret) / pow);     // A**B = exp[B log A]
  ret = temp * temp;                            // Squared!
  gsl_integration_workspace_free(gsl_ws_int);

  return ret;
}
示例#17
0
double growth(const double a)
{
  // Compute integral of D_tilda(a)
  // growth_factor = D_tilda(a)/D_tilda(1.0)

  const double om= cosmology_omega_m();
  const double hubble_a= sqrt(om/(a*a*a) + 1.0 - om);

  const int worksize= 1000;
  double result, abserr;

  gsl_integration_workspace *workspace=
    gsl_integration_workspace_alloc(worksize);

  gsl_function F;
  F.function = &growth_integrand;
  F.params= (void*) &om;

  gsl_integration_qag(&F, 0, a, 0, 1.0e-8, worksize, GSL_INTEG_GAUSS41,
		      workspace, &result, &abserr);

  gsl_integration_workspace_free(workspace);

  return hubble_a * result;
}
示例#18
0
double
integrate (gsl_function * f, double a, double b)
{
  double res = 0, err = 0;
  double tol = 1e-12;
  gsl_integration_qag (f, a, b, 0, tol, 1000, 0,  w, &res, &err);
  return res;
}
示例#19
0
double AT_KatzModel_CucinottaExtTarget_inactivation_cross_section_m2(
    const double  a0_m,
    const double  KatzPoint_r_min_m,
    const double  max_electron_range_m,
    const double  beta,
    const double  C_norm,
    const double  Cucinotta_plateau_Gy,
    const double  KatzPoint_point_coeff_Gy,
    const double  D0_characteristic_dose_Gy,
    const double  c_hittedness,
    const double  m_number_of_targets){

  double low_lim_m = 0.01*a0_m;
  gsl_set_error_handler_off();

  double integral_m2;
  double error;
  gsl_integration_workspace *w1 = gsl_integration_workspace_alloc (1000);
  gsl_function F;
  F.function = &AT_KatzModel_CucinottaExtTarget_inactivation_cross_section_integrand_m;

  AT_KatzModel_CucinottaExtTarget_inactivation_probability_parameters inact_prob_parameters;

  inact_prob_parameters.a0_m                       =  a0_m;
  inact_prob_parameters.KatzPoint_r_min_m          =  KatzPoint_r_min_m;
  inact_prob_parameters.max_electron_range_m       =  max_electron_range_m;
  inact_prob_parameters.beta                       =  beta;
  inact_prob_parameters.C_norm                     =  C_norm;
  inact_prob_parameters.Cucinotta_plateau_Gy       =  Cucinotta_plateau_Gy;
  inact_prob_parameters.KatzPoint_coeff_Gy         =  KatzPoint_point_coeff_Gy;
  inact_prob_parameters.D0_characteristic_dose_Gy  =  D0_characteristic_dose_Gy;
  inact_prob_parameters.c_hittedness               =  c_hittedness;
  inact_prob_parameters.m_number_of_targets        =  m_number_of_targets;

  F.params = (void*)(&inact_prob_parameters);
  int status = gsl_integration_qag (&F, low_lim_m, max_electron_range_m + a0_m, 0, 1e-4, 1000, GSL_INTEG_GAUSS21, w1, &integral_m2, &error);
  if (status == GSL_EROUND || status == GSL_ESING){
#ifndef NDEBUG
    fprintf(stderr,"Error in AT_KatzModel_CucinottaExtTarget_inactivation_cross_section_m2: integration from %g to %g [m] + %g [m]\n", low_lim_m, max_electron_range_m, a0_m);
#endif
    integral_m2 = 0.0;
  }
  gsl_integration_workspace_free (w1);

  const long    gamma_model                =  GR_GeneralTarget;
  const double  gamma_parameters[5]        =  { 1.0, D0_characteristic_dose_Gy, c_hittedness, m_number_of_targets, 0.0};
  double        inactivation_probability_plateau;
  const long    n_tmp                      =  1;
  AT_gamma_response(  n_tmp,
      &Cucinotta_plateau_Gy,
      gamma_model,
      gamma_parameters,
      false,
      &inactivation_probability_plateau);

 return 2.0 * M_PI * integral_m2 + M_PI * gsl_pow_2(0.01*a0_m) * inactivation_probability_plateau;

}
示例#20
0
double tau_e(float zstart, float zend, float *zarry, float *xHarry, int len){
  double prehelium, posthelium, error;
  gsl_function F;
  double rel_tol  = 1e-3; //<- relative tolerance
  gsl_integration_workspace * w 
    = gsl_integration_workspace_alloc (1000);
  tau_e_params p;

  if (zstart >= zend){
    fprintf(stderr, "Error in function taue! First parameter must be smaller than the second.\n");
    return 0;
  }

  F.function = &dtau_e_dz;
  p.z = zarry;
  p.xH = xHarry;
  p.len = len;
  F.params = &p;
  if ((len > 0) && zarry)
    zend = zarry[len-1] - FRACT_FLOAT_ERR;

    

  if (zend > Zreion_HeII){// && (zstart < Zreion_HeII)){
    if (zstart < Zreion_HeII){
      gsl_integration_qag (&F, Zreion_HeII, zstart, 0, rel_tol,
			   1000, GSL_INTEG_GAUSS61, w, &prehelium, &error); 
      gsl_integration_qag (&F, zend, Zreion_HeII, 0, rel_tol,
			   1000, GSL_INTEG_GAUSS61, w, &posthelium, &error); 
    }
    else{
      prehelium = 0;
      gsl_integration_qag (&F, zend, zstart, 0, rel_tol,
			   1000, GSL_INTEG_GAUSS61, w, &posthelium, &error); 
    }
  }
  else{
    posthelium = 0;
    gsl_integration_qag (&F, zend, zstart, 0, rel_tol,
			 1000, GSL_INTEG_GAUSS61, w, &prehelium, &error); 
  }
  gsl_integration_workspace_free (w);

  return SIGMAT * ( (N_b0+He_No)*prehelium + N_b0*posthelium );
}
示例#21
0
local double dsphr(double r, double mtot, double alpha, double zdisk,
		 gsl_integration_workspace *wksp)
{
  double params[3] = { alpha, zdisk, r }, result, abserr;
  gsl_function dsint_func = { &dsint, params };

  assert(gsl_integration_qag(&dsint_func, 0.0, r,
			     0.0, ERRTOL, NWKSP, GSL_INTEG_GAUSS61,
			     wksp, &result, &abserr) == GSL_SUCCESS);
  return (alpha*alpha * mtot * result / (4 * M_PI * zdisk * r));
}
示例#22
0
local double msphr(double r, double mtot, double alpha, double zdisk,
		 gsl_integration_workspace *wksp)
{
  double params[3] = { alpha, zdisk, r }, result, abserr;
  gsl_function msint_func = { &msint, params };

  assert(gsl_integration_qag(&msint_func, 0.0, (double) r,
			     0.0, ERRTOL, NWKSP, GSL_INTEG_GAUSS61,
			     wksp, &result, &abserr) == GSL_SUCCESS);
  return (mtot * result / zdisk);
}
示例#23
0
double do_xi_mm_integral(double lkmin, double lkmax, integrand_params *params,gsl_integration_workspace *w){
  //Define the function to be integrated.
  gsl_function F;
  F.function=&xi_mm_integrand;
  F.params=params;
  double result, abserr;
  //Integrate it.
  int status = gsl_integration_qag(&F,lkmin,lkmax,TOL,TOL/10.,workspace_size,6,w,&result,&abserr);
  //Check for errors.
  if(status){fprintf(stderr,"Error in gsl integration.\n");exit(status);}
  //printf("status = %d\nresult = %e\tabserr=%e\n",status,result,abserr);//Used for debugging.
  return result;
}
示例#24
0
//This function is the integrand of Sigma (R)
double integrand(double rz, void * params){ 
  //Acquire the parameters
  integrand_params*pars = (integrand_params *)params;
  pars->r_z = rz;//Set the current r_z
  gsl_integration_workspace *w = pars->w2;
  gsl_function F;
  F.function = &integrand_offset;
  F.params=pars;
  double result,abserr;
  //int status = gsl_integration_qags(&F,0,2*PI,1e-6,1e-7,workspace_size,/*6,*/w,&result,&abserr);
  int status = gsl_integration_qag(&F,0,2*PI,TOL2,TOL2/10.,workspace_size,6,w,&result,&abserr);
  if(status){fprintf(stderr,"Error in offset integration.\n");exit(status);}
  return result/(2.*PI);
}
示例#25
0
    virtual int exec(double* integral,double* error){
        assert(ncomp==1 && ndim == 1); // gsl 1d integration...
        gsl_1d_integrand_wrapper iw;
        iw.integrand = integrand;
        iw.params = params;

        gsl_integration_workspace* w = gsl_integration_workspace_alloc(limit);
        gsl_function F;
        F.function= gsl_1d_integrand_wrapper::f;
        F.params = (void*) &iw;

        gsl_integration_qag(&F,0,1,epsabs,epsrel,limit,key,w,integral,error);
        gsl_integration_workspace_free(w);
        return 0; // succes!
    }
示例#26
0
double d_L(float z){
  double result, error;
  gsl_function F;
  double rel_tol  = FRACT_FLOAT_ERR; //<- relative tolerance
  gsl_integration_workspace * w 
    = gsl_integration_workspace_alloc (1000);

  F.function = &d_L_derivs;

  gsl_integration_qag (&F, 0, z, 0, rel_tol,
		       1000, GSL_INTEG_GAUSS61, w, &result, &error); 
  gsl_integration_workspace_free (w);

  return C * (1+z) * result / CMperMPC;
}
示例#27
0
static double window_magnification(double chi,RunParams *par,int i_window)
{
  double result,eresult;
  IntLensPar ip;
  gsl_function F;
  gsl_integration_workspace *w=gsl_integration_workspace_alloc(1000);

  ip.par=par;
  ip.chi=chi;
  ip.i_window=i_window;
  F.function=&integrand_wm;
  F.params=&ip;
  gsl_integration_qag(&F,chi,par->chi_horizon,0,1E-4,1000,GSL_INTEG_GAUSS41,w,&result,&eresult);
  gsl_integration_workspace_free(w);
  return result;
}
示例#28
0
/**
 * nc_cluster_abundance_lnM_p_d2n:
 * @cad: a #NcClusterAbundance
 * @cosmo: a #NcHICosmo
 * @clusterz: a #NcClusterRedshift
 * @clusterm: a #NcClusterMass 
 * @lnM_obs: (array) (element-type gdouble): logarithm base e of the observed mass
 * @lnM_obs_params: (array) (element-type gdouble): other information of the observed mass, such as its error
 * @z: redshift
   *
 * This function computes $ \int_{\ln M^{obs} - 7\sigma_{\ln M}}^{\ln M^{obs} + 7\sigma_{\ln M}} d\ln M \,
 * \frac{d^2N}{dzdlnM} * P(\ln M^{obs}|\ln M) $. The integral limits were determined requiring a precision
 * to five decimal places.
 *
 * Returns: a gdouble which corresponds to $ \int_{\ln M^{obs} - 7\sigma_{\ln M}}^{\ln M^{obs} + 7\sigma_{\ln M}} d\ln M \,
 * \frac{d^2N}{dzdlnM} * P(\ln M^{obs}|\ln M) $.
 */
gdouble
nc_cluster_abundance_lnM_p_d2n (NcClusterAbundance *cad, NcHICosmo *cosmo, NcClusterRedshift *clusterz, NcClusterMass *clusterm, gdouble *lnM_obs, gdouble *lnM_obs_params, gdouble z)
{
  observables_integrand_data obs_data;
  gdouble d2N, lnMl, lnMu, err;
  gsl_function F;
  gsl_integration_workspace **w = ncm_integral_get_workspace ();

  obs_data.cad            = cad;
  obs_data.cosmo          = cosmo;
  obs_data.clusterz       = clusterz;
  obs_data.clusterm       = clusterm;
  obs_data.lnM_obs        = lnM_obs;
  obs_data.lnM_obs_params = lnM_obs_params;
  obs_data.z              = z;

  F.function = &_nc_cluster_abundance_lnM_p_d2n_integrand;
  F.params = &obs_data;

  nc_cluster_mass_p_limits (clusterm, cosmo, lnM_obs, lnM_obs_params, &lnMl, &lnMu);

  gsl_integration_qag (&F, lnMl, lnMu, 0.0, NCM_DEFAULT_PRECISION, NCM_INTEGRAL_PARTITION, _NC_CLUSTER_ABUNDANCE_DEFAULT_INT_KEY, *w, &d2N, &err);
  ncm_memory_pool_return (w);

#define VECTOR (NCM_MODEL (msz)->params)
#define A_SZ   (ncm_vector_get (VECTOR, NC_CLUSTER_MASS_BENSON_A_SZ))
#define B_SZ   (ncm_vector_get (VECTOR, NC_CLUSTER_MASS_BENSON_B_SZ))
#define C_SZ   (ncm_vector_get (VECTOR, NC_CLUSTER_MASS_BENSON_C_SZ))
#define D_SZ   (ncm_vector_get (VECTOR, NC_CLUSTER_MASS_BENSON_D_SZ))
if (FALSE)
  {
    NcClusterMassBenson *msz = NC_CLUSTER_MASS_BENSON (clusterm);
    const gdouble xi = 5.0;//lnM_obs[0];
    const gdouble zeta = sqrt (xi * xi - 3) - 7.0 * D_SZ;
    const gdouble E0 = nc_hicosmo_E (cosmo, msz->z0); 
    const gdouble E = nc_hicosmo_E (cosmo, z);
    const gdouble lnzeta = log (zeta);
    const gdouble lnM = log (msz->M0) + (lnzeta - log (A_SZ) - C_SZ * log (E / E0)) / B_SZ;
    const gdouble d2N_lnM = nc_halo_mass_function_d2n_dzdlnM (cad->mfp, cosmo, lnM, z);

    printf ("xi % 8.5g zeta % 8.5g M % 8.5g [% 8.5g % 8.5g] : d2N_lnM % 8.5g d2N_xi % 8.5g r % 8.5g m2lnL % 8.5g\n",
            xi, zeta, exp (lnM), exp (lnMl), exp (lnMu), d2N_lnM, d2N, d2N / d2N_lnM, -2.0 * log (d2N));
  }


  return d2N;
}
示例#29
0
/*
 * call the integration function according to the parameters.
 */
static int call_integration_func(gmdi_multi_dim_inte_param* params)
{
    gmdi_one_inte_param *               oip = params->oip + params->intern.dim;

    int                                 ret;

    double                              inte_limit_low  = call_gmdi_function_or_constant(&oip->x0, params->intern.x);
    double                              inte_limit_high = call_gmdi_function_or_constant(&oip->x1, params->intern.x);

    gsl_function                        gf;

    gf.function = big_g;
    gf.params = params;

    switch (oip->inte_func)
    {
    case GMDI_INTE_FUNCTIONS_QNG:
        ret = gsl_integration_qng(&gf,
                inte_limit_low,
                inte_limit_high,
                oip->epsabs,
                oip->epsrel,
                params->intern.results + params->intern.dim,
                params->intern.abserrs + params->intern.dim,
                &params->neval);

        break;
    case GMDI_INTE_FUNCTIONS_QAG:

        ret = gsl_integration_qag(&gf,
                inte_limit_low,
                inte_limit_high,
                oip->epsabs,
                oip->epsrel,
                oip->limit,
                oip->key,
                oip->intern.giw,
                params->intern.results + params->intern.dim,
                params->intern.abserrs + params->intern.dim);
        break;

    default: /* No proper inte_func is found */
        GSL_ERROR("Invalid inte_func is specified", GSL_EINVAL);
    }

    return ret;
}
示例#30
0
文件: cosmo.c 项目: phyytang/l-picola
// Growth factor integral
// ======================
double growthDtemp(double a) {

  double alpha = 0.0;
  double result, error;

  gsl_function F;
  gsl_integration_workspace * w = gsl_integration_workspace_alloc (5000);
     
  F.function = &growthDtempfunc;
  F.params = &alpha;
     
  gsl_integration_qag(&F,0.0,a,0,1e-5,5000,6,w,&result,&error); 
      
  gsl_integration_workspace_free (w);
     
  return result;
}