Пример #1
0
double M_sc(double       z,
            cosmo_info **cosmo,
            int          mode,
            int          component){
  int     i;
  int     n_k;
  size_t  n_k_dim;
  double *lM_k;
  double *lk_P;
  double *sigma2;
  interp_info *interp;
  double  delta_sc=1.686;
  double  b_z;
  double  r_val;
  char    mode_name[ADaPS_NAME_LENGTH];
  char    component_name[ADaPS_NAME_LENGTH];
  char    sigma2_name[ADaPS_NAME_LENGTH];
  static double M_sc_last;
  static double z_last=-42.;

  if(z!=z_last){
    // Set/initialize variance
    pspec_names(mode,component,mode_name,component_name);
    sprintf(sigma2_name,"sigma2_k_%s_%s_interp",mode_name,component_name);
    if(!ADaPS_exist(*cosmo,sigma2_name))
      init_power_spectrum_variance(cosmo,z,mode,component);
    interp   =(interp_info *)ADaPS_fetch(*cosmo,sigma2_name);
    b_z      =linear_growth_factor(z,*cosmo);
    r_val    =bisect_array(interp,delta_sc*delta_sc/(b_z*b_z),1e-4);
    M_sc_last=M_of_k(take_alog10(r_val),z,*cosmo);
    z_last   =z;
  }

  return(M_sc_last);
}
Пример #2
0
void init_gbpCosmo2gbpCosmo(cosmo_info      **cosmo_source,
                            cosmo_info      **cosmo_target,
                            double            z_min,
                            double            M_min,
                            double            M_max,
                            gbpCosmo2gbpCosmo_info *gbpCosmo2gbpCosmo){
   SID_log("Initializing cosmology scaling...",SID_LOG_OPEN|SID_LOG_TIMER);
   SID_set_verbosity(SID_SET_VERBOSITY_RELATIVE,-1);

   // Store some infor in the gbpCosmo2gbpCosmo_info structure
   gbpCosmo2gbpCosmo->M_min       =M_min;
   gbpCosmo2gbpCosmo->M_max       =M_max;
   gbpCosmo2gbpCosmo->z_min       =z_min;
   gbpCosmo2gbpCosmo->cosmo_source=(*cosmo_source);
   gbpCosmo2gbpCosmo->cosmo_target=(*cosmo_target);

   // Perform minimization
   //const gsl_multimin_fminimizer_type *T=gsl_multimin_fminimizer_nmsimplex2;
   const gsl_multimin_fminimizer_type *T=gsl_multimin_fminimizer_nmsimplex;
   gsl_multimin_fminimizer            *s = NULL;
   gsl_vector *ss, *x;
   gsl_multimin_function minex_func;
 
   // Starting point 
   x = gsl_vector_alloc (2);
   gsl_vector_set (x, 0, 1.);    // inv_s
   gsl_vector_set (x, 1, z_min); // z_scaled
 
   // Set initial step sizes to 1 
   ss = gsl_vector_alloc (2);
   gsl_vector_set_all (ss, 1.0);

   // Set parameters
   init_gbpCosmo2gbpCosmo_integrand_params params;
   params.cosmo_source=cosmo_source;
   params.cosmo_target=cosmo_target;
   params.z_source    =z_min;
   params.R_1         =R_of_M(M_min,*cosmo_source);
   params.R_2         =R_of_M(M_max,*cosmo_source);
   params.inv_s       =gsl_vector_get(x,0);
   params.z_target    =gsl_vector_get(x,1);
   params.n_int       =100;
   params.wspace      =gsl_integration_workspace_alloc(params.n_int);

   // Initialize method
   minex_func.n      = 2;
   minex_func.f      = init_gbpCosmo2gbpCosmo_minimize_function;
   minex_func.params = (void *)(&params);
   s                 = gsl_multimin_fminimizer_alloc (T, 2);
   gsl_multimin_fminimizer_set(s,&minex_func,x,ss);

   // Perform minimization 
   double size;
   int    status;
   size_t iter    =  0;
   size_t iter_max=200;
   do{
       iter++;
       status=gsl_multimin_fminimizer_iterate(s);
       if(status) 
          SID_trap_error("Error encountered during minimisation in init_gbpCosmo2gbpCosmo() (status=%d).",ERROR_LOGIC,status);
       size   = gsl_multimin_fminimizer_size(s);
       status = gsl_multimin_test_size(size,1e-2);
   } while(status==GSL_CONTINUE && iter<=iter_max);
   if(status!=GSL_SUCCESS)
      SID_trap_error("Failed to converge during minimisation in init_gbpCosmo2gbpCosmo() (status=%d,iter=%d).",ERROR_LOGIC,status,iter);

   // Finalize results   
   double Omega_M_source =    ((double *)ADaPS_fetch(*cosmo_source,"Omega_M") )[0];
   double H_Hubble_source=1e2*((double *)ADaPS_fetch(*cosmo_source,"h_Hubble"))[0];
   double Omega_M_target =    ((double *)ADaPS_fetch(*cosmo_target,"Omega_M") )[0];
   double H_Hubble_target=1e2*((double *)ADaPS_fetch(*cosmo_target,"h_Hubble"))[0];
   gbpCosmo2gbpCosmo->s_L         =1./gsl_vector_get(s->x,0);
   gbpCosmo2gbpCosmo->s_M         =(Omega_M_target*H_Hubble_target)/(Omega_M_source*H_Hubble_source)*pow((gbpCosmo2gbpCosmo->s_L),3.);
   gbpCosmo2gbpCosmo->z_min_scaled=gsl_vector_get(s->x,1);;

   // Calculate growth factors needed for
   //    determining redshift mappings
   gbpCosmo2gbpCosmo->D_prime_z_min=linear_growth_factor(z_min,                    *cosmo_target);
   gbpCosmo2gbpCosmo->D_z_scaled   =linear_growth_factor(gbpCosmo2gbpCosmo->z_min_scaled,*cosmo_source);
   gbpCosmo2gbpCosmo->D_ratio      =gbpCosmo2gbpCosmo->D_prime_z_min/gbpCosmo2gbpCosmo->D_z_scaled;

   // Clean-up
   gsl_vector_free(x);
   gsl_vector_free(ss);
   gsl_multimin_fminimizer_free(s);
   gsl_integration_workspace_free(params.wspace);
   SID_set_verbosity(SID_SET_VERBOSITY_DEFAULT);
   SID_log("Done.",SID_LOG_CLOSE);
}