GammaSpline * gamma_spline_new (int size) { GammaSpline *gs = g_slice_new(GammaSpline); gs->k = double_array_calloc(size); gs->phi = double_array_calloc(size); gs->Wxr = double_array_calloc(size); gs->Wxi = double_array_calloc(size); gs->Wyr = double_array_calloc(size); gs->Wyi = double_array_calloc(size); gs->Wzr = double_array_calloc(size); gs->Wzi = double_array_calloc(size); gs->phi_spline = gsl_interp_alloc(gsl_interp_akima,size); gs->phi_accel = gsl_interp_accel_alloc(); gs->wx_spline_re = gsl_interp_alloc(gsl_interp_akima,size); gs->w_accel = gsl_interp_accel_alloc(); gs->wx_spline_im = gsl_interp_alloc(gsl_interp_akima,size); gs->wy_spline_re = gsl_interp_alloc(gsl_interp_akima,size); gs->wy_spline_im = gsl_interp_alloc(gsl_interp_akima,size); gs->wz_spline_re = gsl_interp_alloc(gsl_interp_akima,size); gs->wz_spline_im = gsl_interp_alloc(gsl_interp_akima,size); return gs; }
ODEparams * init(int nap,double * alpha,double * talpha, int nbp, double* beta, double *tbeta,double gamma, double x0,double y0) { ODEparams * pa= (ODEparams*)malloc(sizeof(ODEparams)); pa->gamma=gamma; pa->x0=x0; pa->y0=y0; pa->nap=nap; pa->nbp=nbp; pa->alpha=calloc(nap,sizeof(double)); pa->talpha=calloc(nap,sizeof(double)); pa->beta=calloc(nbp,sizeof(double)); pa->tbeta=calloc(nbp,sizeof(double)); int i; memcpy(pa->alpha,alpha,nap*sizeof(double)); memcpy(pa->talpha,talpha,nap*sizeof(double)); memcpy(pa->beta,beta,nbp*sizeof(double)); memcpy(pa->tbeta,tbeta,nbp*sizeof(double)); pa->a_acc=gsl_interp_accel_alloc (); pa->b_acc=gsl_interp_accel_alloc (); pa->a_spline = gsl_spline_alloc (gsl_interp_cspline,nap); gsl_spline_init (pa->a_spline, pa->talpha, pa->alpha, pa->nap); pa->b_spline = gsl_spline_alloc (gsl_interp_cspline,nbp); gsl_spline_init (pa->b_spline, pa->tbeta, pa->beta, pa->nbp); pa->gamma=gamma; pa->x0=x0; pa->y0=y0; return pa; }
/** * Tests that a given interpolation type reproduces the data points it is given, * and then tests that it correctly reproduces additional values. * * @param xarr the x values of the points that define the function * @param yarr the y values of the points that define the function * @param zarr the values of the function at the points specified by xarr and yarr * @param xsize the length of xarr * @param ysize the length of yarr * @param xval the x values of additional points at which to calculate interpolated values * @param yval the y values of additional points at which to calculate interpolated values * @param zval the expected results of the additional interpolations * @param zxval the expected results of the x derivative calculations * @param zyval the expected results of the y derivative calculations * @param zxxval the expected results of the xx derivative calculations * @param zyyval the expected results of the yy derivative calculations * @param zxyval the expected results of the xy derivative calculations * @param test_size the length of xval, yval, zval, etc. * @param T the interpolation type */ int test_interp2d(const double xarr[], const double yarr[], const double zarr[], // interpolation data size_t xsize, size_t ysize, // sizes of xarr and yarr const double xval[], const double yval[], // test points const double zval[], // expected results const double zxval[], const double zyval[], const double zxxval[], const double zyyval[], const double zxyval[], size_t test_size, // number of test points const interp2d_type* T) { gsl_interp_accel *xa, *ya; int status = 0; size_t xi, yi, zi, i; xa = gsl_interp_accel_alloc(); ya = gsl_interp_accel_alloc(); interp2d* interp = interp2d_alloc(T, xsize, ysize); interp2d_spline* interp_s = interp2d_spline_alloc(T, xsize, ysize); unsigned int min_size = interp2d_type_min_size(T); gsl_test_int(min_size, T->min_size, "interp2d_type_min_size on %s", interp2d_name(interp)); interp2d_init(interp, xarr, yarr, zarr, xsize, ysize); interp2d_spline_init(interp_s, xarr, yarr, zarr, xsize, ysize); // First check that the interpolation reproduces the given points for (xi = 0; xi < xsize; xi++) { double x = xarr[xi]; for (yi = 0; yi < ysize; yi++) { double y = yarr[yi]; zi = INDEX_2D(xi, yi, xsize, ysize); test_single_low_level(&interp2d_eval, &interp2d_eval_e, interp, xarr, yarr, zarr, x, y, xa, ya, zarr, zi); test_single_low_level(&interp2d_eval_no_boundary_check, &interp2d_eval_e_no_boundary_check, interp, xarr, yarr, zarr, x, y, xa, ya, zarr, zi); test_single_high_level(&interp2d_spline_eval, &interp2d_spline_eval_e, interp_s, x, y, xa, ya, zarr, zi); } } // Then check additional points provided for (i = 0; i < test_size; i++) { double x = xval[i]; double y = yval[i]; test_single_low_level(&interp2d_eval, &interp2d_eval_e, interp, xarr, yarr, zarr, x, y, xa, ya, zval, i); test_single_low_level(&interp2d_eval_deriv_x, &interp2d_eval_deriv_x_e, interp, xarr, yarr, zarr, x, y, xa, ya, zxval, i); test_single_low_level(&interp2d_eval_deriv_y, &interp2d_eval_deriv_y_e, interp, xarr, yarr, zarr, x, y, xa, ya, zyval, i); test_single_low_level(&interp2d_eval_deriv_xx,&interp2d_eval_deriv_xx_e, interp, xarr, yarr, zarr, x, y, xa, ya, zxxval, i); test_single_low_level(&interp2d_eval_deriv_yy,&interp2d_eval_deriv_yy_e, interp, xarr, yarr, zarr, x, y, xa, ya, zyyval, i); test_single_low_level(&interp2d_eval_deriv_xy,&interp2d_eval_deriv_xy_e, interp, xarr, yarr, zarr, x, y, xa, ya, zxyval, i); test_single_high_level(&interp2d_spline_eval, &interp2d_spline_eval_e, interp_s, x, y, xa, ya, zval, i); test_single_high_level(&interp2d_spline_eval_deriv_x, &interp2d_spline_eval_deriv_x_e, interp_s, x, y, xa, ya, zxval, i); test_single_high_level(&interp2d_spline_eval_deriv_y, &interp2d_spline_eval_deriv_y_e, interp_s, x, y, xa, ya, zyval, i); test_single_high_level(&interp2d_spline_eval_deriv_xx,&interp2d_spline_eval_deriv_xx_e, interp_s, x, y, xa, ya, zxxval, i); test_single_high_level(&interp2d_spline_eval_deriv_yy,&interp2d_spline_eval_deriv_yy_e, interp_s, x, y, xa, ya, zyyval, i); test_single_high_level(&interp2d_spline_eval_deriv_xy,&interp2d_spline_eval_deriv_xy_e, interp_s, x, y, xa, ya, zxyval, i); test_single_low_level(&interp2d_eval_no_boundary_check, &interp2d_eval_e_no_boundary_check, interp, xarr, yarr, zarr, x, y, xa, ya, zval, i); } gsl_interp_accel_free(xa); gsl_interp_accel_free(ya); interp2d_free(interp); return status; }
static float interp_demData(float *demData, int nl, int ns, double l, double s) { if (l<0 || l>=nl-1 || s<0 || s>=ns-1) { return 0; } int ix = (int)s; int iy = (int)l; int bilinear = l<3 || l>=nl-3 || s<3 || s>=ns-3; //int bilinear = 1; if (bilinear) { float p00 = demData[ix + ns*(iy )]; float p10 = demData[ix+1 + ns*(iy )]; float p01 = demData[ix + ns*(iy+1)]; float p11 = demData[ix+1 + ns*(iy+1)]; return (float)bilinear_interp_fn(s-ix, l-iy, p00, p10, p01, p11); } else { double ret, x[4], y[4], xi[4], yi[4]; int ii; for (ii=0; ii<4; ++ii) { y[0] = demData[ix-1 + ns*(iy+ii-1)]; y[1] = demData[ix + ns*(iy+ii-1)]; y[2] = demData[ix+1 + ns*(iy+ii-1)]; y[3] = demData[ix+2 + ns*(iy+ii-1)]; x[0] = ix - 1; x[1] = ix; x[2] = ix + 1; x[3] = ix + 2; gsl_interp_accel *acc = gsl_interp_accel_alloc (); gsl_spline *spline = gsl_spline_alloc (gsl_interp_cspline, 4); gsl_spline_init (spline, x, y, 4); yi[ii] = gsl_spline_eval_check(spline, s, acc); gsl_spline_free (spline); gsl_interp_accel_free (acc); xi[ii] = iy + ii - 1; } gsl_interp_accel *acc = gsl_interp_accel_alloc (); gsl_spline *spline = gsl_spline_alloc (gsl_interp_cspline, 4); gsl_spline_init (spline, xi, yi, 4); ret = gsl_spline_eval_check(spline, l, acc); gsl_spline_free (spline); gsl_interp_accel_free (acc); return (float)ret; } asfPrintError("Impossible."); }
Particles::Particles() { /* Default values */ eElectronMax = 100000.; SpectralIndex = 2.000; Tmin = 1.; CutOffFactor = 1000.; TminInternal = 1.e-10; TmaxInternal = 1.e100; EminInternal = 1.e-3; energyMarginFactor = 1.e-3; energyMargin = 1.; ebins = 100; SACELI_Told = 0.; R = -1.; V = -1.; gslmemory=5000; QUIETMODE = false; EminConstantForNormalisationOnly = false; DEBUG = false; ICLossLookup = NULL; LumLookup = NULL; NLookup = NULL; eMaxLookup = NULL; BFieldLookup = NULL; RLookup = NULL; VLookup = NULL; escapeTimeLookup = NULL; integratorTolerance = 5.e-2; ParticleSpectrum.clear(); ParticleSpectrum.resize(0); ICLossVector.resize(0); LumVector.resize(0); NVector.resize(0); BVector.resize(0); eMaxVector.resize(0); escapeTimeVector.resize(0); RVector.resize(0); VVector.resize(0); SpectralIndex2 = eBreak = TminConstant = adLossCoeff = EminConstant = eMaxConstant = 0.; escapeTime = escapeTimeConstant = EnergyAxisLowerBoundary = EnergyAxisUpperBoundary = 0.; eBreakS2 = eBreak2mS2 = eBreakS = eBreak2mS = emin2mS2 = emin2mS = emineBreak2mS2 = 0.; eBreak2mSInd2 = emin2mSInd2 = emineBreak2mSInd2 = fS = fS2 = bremsl_epf = bremsl_eef = 0.; LumConstant = BConstant = NConstant = VConstant = RConstant = 0.; accIC = gsl_interp_accel_alloc(); accLum = gsl_interp_accel_alloc(); accN = gsl_interp_accel_alloc(); accBField = gsl_interp_accel_alloc(); acceMax = gsl_interp_accel_alloc(); accescapeTime = gsl_interp_accel_alloc(); accR = gsl_interp_accel_alloc(); accV = gsl_interp_accel_alloc(); accTr = gsl_interp_accel_alloc(); accTrInv = gsl_interp_accel_alloc(); }
int load_lens(int l_size ,int* l_values){ double* lens_data = malloc( sizeof(double)*MAXLINES*3); int* lens_len = malloc( sizeof(int)); load_txt_dbl(lens_data_file, 3, lens_data, lens_len); int lens_size = *lens_len; int lmax = (int)get_lmax(); // printf("lmax %d\t%d\n",lmax,lens_size); double l_raw[lens_size]; double cltt_raw[lens_size]; double cltp_raw[lens_size]; int i,j; double pt; j=0; for (i=0; i<lmax+1; i++){ l_raw[i] = lens_data[j++]; cltt_raw[i] = lens_data[j++]; cltp_raw[i] = lens_data[j++]; } if (l_values[l_size-1]>l_raw[lmax]){ printf("lens do not contain enough l's, max data %d max lens: %d\n", l_values[l_size-1], (int)l_raw[lmax]); return 1; exit; } gsl_spline* sptt = gsl_spline_alloc (gsl_interp_cspline, lmax+1); gsl_spline* sptp = gsl_spline_alloc (gsl_interp_cspline, lmax+1); gsl_interp_accel* acctt = gsl_interp_accel_alloc(); gsl_interp_accel* acctp = gsl_interp_accel_alloc(); gsl_spline_init(sptt,l_raw,cltt_raw,lmax+1); gsl_spline_init(sptp,l_raw,cltp_raw,lmax+1); for (i=0; i<l_size; i++){ pt = (double)l_values[i]; lens_tt[i] = 0.0; lens_tp[i] = 0.0; if(pt!=0){ lens_tt[i] = gsl_spline_eval(sptt,pt,acctt); lens_tp[i] = gsl_spline_eval(sptp,pt,acctp); } } gsl_spline_free(sptt); gsl_spline_free(sptp); gsl_interp_accel_free(acctt); gsl_interp_accel_free(acctp); return 0; }
vector<carmen_ackerman_path_point_t> simulate_car_from_parameters(TrajectoryLookupTable::TrajectoryDimensions &td, TrajectoryLookupTable::TrajectoryControlParameters &tcp, double v0, double i_phi, TrajectoryLookupTable::CarLatencyBuffer car_latency_buffer, bool display_phi_profile) { vector<carmen_ackerman_path_point_t> path; if (!tcp.valid) { printf("Warning: invalid TrajectoryControlParameters tcp in simulate_car_from_parameters()\n"); return (path); } // Create phi profile gsl_interp_accel *acc; gsl_spline *phi_spline; if (tcp.has_k1) { double knots_x[4] = {0.0, tcp.tt / 4.0, tcp.tt / 2.0, tcp.tt}; double knots_y[4] = {i_phi, tcp.k1, tcp.k2, tcp.k3}; acc = gsl_interp_accel_alloc(); const gsl_interp_type *type = gsl_interp_cspline; phi_spline = gsl_spline_alloc(type, 4); gsl_spline_init(phi_spline, knots_x, knots_y, 4); } else { double knots_x[3] = {0.0, tcp.tt / 2.0, tcp.tt}; double knots_y[3] = {i_phi, tcp.k2, tcp.k3}; acc = gsl_interp_accel_alloc(); const gsl_interp_type *type = gsl_interp_cspline; phi_spline = gsl_spline_alloc(type, 3); gsl_spline_init(phi_spline, knots_x, knots_y, 3); } print_phi_profile_temp(phi_spline, acc, tcp.tt, display_phi_profile); Command command; Robot_State robot_state; double distance_traveled = compute_path_via_simulation(robot_state, command, path, tcp, phi_spline, acc, v0, i_phi, car_latency_buffer); gsl_spline_free(phi_spline); gsl_interp_accel_free(acc); td.dist = sqrt(robot_state.pose.x * robot_state.pose.x + robot_state.pose.y * robot_state.pose.y); td.theta = atan2(robot_state.pose.y, robot_state.pose.x); td.d_yaw = robot_state.pose.theta; td.phi_i = i_phi; td.v_i = v0; tcp.vf = command.v; tcp.sf = distance_traveled; td.control_parameters = tcp; return (path); }
UNUSED static REAL8 XLALSimInspiralNRWaveformGetInterpValueFromGroupAtPoint( UNUSED LALH5File* file, /**< Pointer to HDF5 file */ UNUSED const char *groupName, /**< Name of group in HDF file */ UNUSED REAL8 ref_point /**< Point at which to evaluate */ ) { #ifndef LAL_HDF5_ENABLED XLAL_ERROR(XLAL_EFAILED, "HDF5 support not enabled"); #else LALH5File *curr_group = NULL; gsl_vector *curr_t_vec = NULL; gsl_vector *curr_y_vec = NULL; gsl_interp_accel *acc; gsl_spline *spline; REAL8 ret_val; curr_group = XLALH5GroupOpen(file, groupName); ReadHDF5RealVectorDataset(curr_group, "X", &curr_t_vec); ReadHDF5RealVectorDataset(curr_group, "Y", &curr_y_vec); acc = gsl_interp_accel_alloc(); spline = gsl_spline_alloc(gsl_interp_cspline, curr_t_vec->size); gsl_spline_init(spline, curr_t_vec->data, curr_y_vec->data, curr_t_vec->size); ret_val = gsl_spline_eval(spline, ref_point, acc); gsl_vector_free(curr_t_vec); gsl_vector_free(curr_y_vec); gsl_spline_free (spline); gsl_interp_accel_free (acc); return ret_val; #endif }
void spline(double *YY, double *X, double *Y, double *XX, int m1, int m2) { // m1: length of discrete extremas // m2: length of original data points gsl_interp_accel *acc = gsl_interp_accel_alloc (); const gsl_interp_type *t = gsl_interp_cspline; gsl_spline *spline = gsl_spline_alloc (t, m1); /* Core function */ gsl_spline_init (spline, X, Y, m1); double m; if (m1 > 2 ) { for (int j = 0; j < m2; j++) { YY[j] = gsl_spline_eval (spline, XX[j], acc); } // end of for-j } // end of if else { m = (Y[1] - Y[0]) / (X[1] - X[0]); for (int j = 0; j < m2; j++) { YY[j] = Y[0] + m * (XX[j] - X[0]); } // end of for-j } //end of else // delete[] xd; gsl_spline_free (spline); gsl_interp_accel_free (acc); }
// angular average for Mhat in integration region I for given s (<z^n*M> with // n={0,1}) void M_avg_1(complex_spline M, complex *M_avg, double *s, double a, double b, double c, double d, char plusminus, char kappa_pm, int N, int n) { int i, N_int; double eps, error, s_minus, s_plus, sigma; N_int = 1500; eps = 1.0e-10; gsl_interp_accel *acc = gsl_interp_accel_alloc(); gsl_integration_workspace *w = gsl_integration_workspace_alloc(N_int); gsl_function F; gsl_function G; double f_re(double z, void *params) { double sigma = *(double *)params; double f; if (n == 0) { f = gsl_spline_eval(M.re, z, acc); } else if (n == 1) { f = (z - sigma) * gsl_spline_eval(M.re, z, acc); } else if (n == 2) { f = pow(z - sigma, 2.0) * gsl_spline_eval(M.re, z, acc); } // if (isnan(f)==1) { // printf("%d %.3e %.3e\n",n,z,sigma); // } return f; }
void prep_et() { /* Set ups the spline to sample et. */ double et; double gn0 = -1, gt0; slLimit = 6*mu - mu*kn/kt; double *x = (double*)calloc(100, sizeof(double)); double *y = (double*)calloc(100, sizeof(double)); /* Write first point. */ x[0] = 0; y[0] = cos(sqrt(3*kt/meff)*t_col()); /* Calculate intermediate points. */ long i; for (i = 1; i < 100; i++) { gt0 = slLimit/100.0*i; double ratio = fabs(gt0/(double)gn0); et = calculate_et(gn0, gt0); x[i] = ratio; y[i] = et; } /* Write last point. */ x[100] = 6*mu - mu*kn/kt; y[100] = 1 - 3*mu*(1 + calc_en())/x[100]; /* Interpolation with cubic spline. */ acc = gsl_interp_accel_alloc(); spline = gsl_spline_alloc(gsl_interp_cspline, 101); gsl_spline_init(spline, x, y, 101); }
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 }
int main (void) { int i; double xi, yi; double x[10], y[10]; printf ("#m=0,S=2\n"); for (i = 0; i < 10; i++) { x[i] = i + 0.5 * sin (i); y[i] = i + cos (i * i); printf ("%g %g\n", x[i], y[i]); } printf ("#m=1,S=0\n"); { gsl_interp_accel *acc = gsl_interp_accel_alloc (); gsl_spline *spline = gsl_spline_alloc (gsl_interp_cspline, 10); gsl_spline_init (spline, x, y, 10); for (xi = x[0]; xi < x[9]; xi += 0.01) { double yi = gsl_spline_eval (spline, xi, acc); printf ("%g %g\n", xi, yi); } gsl_spline_free (spline); gsl_interp_accel_free(acc); } }
static VALUE rb_gsl_interp_new(int argc, VALUE *argv, VALUE klass) { rb_gsl_interp *sp = NULL; const gsl_interp_type *T = NULL; double *ptrx = NULL, *ptry = NULL; size_t sizex = 0, sizey = 0, size = 0, stride = 1; int i; for (i = 0; i < argc; i++) { switch (TYPE(argv[i])) { case T_STRING: T = get_interp_type(argv[i]); break; case T_FIXNUM: if (T) size = FIX2INT(argv[i]); else T = get_interp_type(argv[i]); break; default: if (ptrx == NULL) { ptrx = get_vector_ptr(argv[i], &stride, &sizex); } else { ptry = get_vector_ptr(argv[i], &stride, &sizey); size = GSL_MIN_INT(sizex, sizey); } break; } } if (size == 0) rb_raise(rb_eRuntimeError, "interp size is not given."); sp = ALLOC(rb_gsl_interp); if (T == NULL) T = gsl_interp_cspline; sp->p = gsl_interp_alloc(T, size); sp->a = gsl_interp_accel_alloc(); if (ptrx && ptry) gsl_interp_init(sp->p, ptrx, ptry, size); return Data_Wrap_Struct(klass, 0, rb_gsl_interp_free, sp); }
/*! \fn void create_linear_spline(double (*func)(double, void *), double *x, double *&y, int n, double *params, gsl_spline *&spline, gsl_interp_accel *&acc) * \brief Routine to create a spline, interpolated linear. */ void create_linear_spline(double (*func)(double, void *), double *x, double *&y, int n, double *params, gsl_spline *&spline, gsl_interp_accel *&acc) { //x contains the locations at which //wish to evaluate the function func() //y is input unallocated //we will allocate it and it will //contain func(x) //n is the size of the array of x and y //params is the array of parameters to pass to //func(x,params) //spline is the unallocated gsl_spline //acc is the unallocated gsl_interp_accel //allocate y y = calloc_double_array(n); //evaluate func at x locations for(int i=0;i<n;i++) y[i] = func(x[i],params); //allocate interpolants spline = gsl_spline_alloc(gsl_interp_cspline,n); acc = gsl_interp_accel_alloc(); //create interpoolation gsl_spline_init(spline, x, y, n); }
int calc_ave_delta_sigma_in_bin(double*R,int NR,double*delta_sigma, double lRlow,double lRhigh, double*ave_delta_sigma){ int status = 0; gsl_spline*spline = gsl_spline_alloc(gsl_interp_cspline,NR); gsl_spline_init(spline,R,delta_sigma,NR); gsl_interp_accel*acc= gsl_interp_accel_alloc(); gsl_integration_workspace * workspace = gsl_integration_workspace_alloc(workspace_size); integrand_params*params=malloc(sizeof(integrand_params)); params->acc=acc; params->spline=spline; params->workspace=workspace; double Rlow=exp(lRlow),Rhigh=exp(lRhigh); do_integral(ave_delta_sigma,lRlow,lRhigh,params); *ave_delta_sigma *= 2./(Rhigh*Rhigh-Rlow*Rlow); gsl_spline_free(spline),gsl_interp_accel_free(acc); gsl_integration_workspace_free(workspace); free(params); return 0; }
void polymodel(void) { gsl_interp_accel *pmsplacc = gsl_interp_accel_alloc(); bodyptr p; real rad, phi, vel, psi, vr, vp, a, E, J; vector rhat, vtmp, vper; for (p = btab; p < NthBody(btab, nbody); p = NextBody(p)) { rad = rad_m(xrandom(0.0, mtot)); phi = gsl_spline_eval(pmspline, (double) rad, pmsplacc); vel = pick_v(phi); psi = pick_psi(); vr = vel * rcos(psi); vp = vel * rsin(psi); Mass(p) = mtot / nbody; pickshell(rhat, NDIM, 1.0); MULVS(Pos(p), rhat, rad); pickshell(vtmp, NDIM, 1.0); a = dotvp(vtmp, rhat); MULVS(vper, rhat, - a); ADDV(vper, vper, vtmp); a = absv(vper); MULVS(vper, vper, vp / a); MULVS(Vel(p), rhat, vr); ADDV(Vel(p), Vel(p), vper); Phi(p) = phi; E = phi + 0.5 * rsqr(vel); J = rad * ABS(vp); Aux(p) = Kprime * rpow(phi1 - E, npol - 1.5) * rpow(J, 2 * mpol); } gsl_interp_accel_free(pmsplacc); }
TransformationModelInterpolated::TransformationModelInterpolated( const TransformationModel::DataPoints & data, const Param & params) { params_ = params; Param defaults; getDefaultParameters(defaults); params_.setDefaults(defaults); // need monotonically increasing x values (can't have the same value twice): map<DoubleReal, vector<DoubleReal> > mapping; for (TransformationModel::DataPoints::const_iterator it = data.begin(); it != data.end(); ++it) { mapping[it->first].push_back(it->second); } size_ = mapping.size(); x_.resize(size_); y_.resize(size_); size_t i = 0; for (map<DoubleReal, vector<DoubleReal> >::const_iterator it = mapping.begin(); it != mapping.end(); ++it, ++i) { x_[i] = it->first; // use average y value: y_[i] = accumulate(it->second.begin(), it->second.end(), 0.0) / it->second.size(); } String interpolation_type = params_.getValue("interpolation_type"); const gsl_interp_type * type; if (interpolation_type == "linear") type = gsl_interp_linear; else if (interpolation_type == "polynomial") type = gsl_interp_polynomial; else if (interpolation_type == "cspline") type = gsl_interp_cspline; else if (interpolation_type == "akima") type = gsl_interp_akima; else { throw Exception::IllegalArgument(__FILE__, __LINE__, __PRETTY_FUNCTION__, "unknown/unsupported interpolation type '" + interpolation_type + "'"); } size_t min_size = type->min_size; if (size_ < min_size) { throw Exception::IllegalArgument(__FILE__, __LINE__, __PRETTY_FUNCTION__, "'" + interpolation_type + "' interpolation model needs at least " + String(min_size) + " data points (with unique x values)"); } interp_ = gsl_interp_alloc(type, size_); acc_ = gsl_interp_accel_alloc(); double * x_start = &(x_[0]), * y_start = &(y_[0]); gsl_interp_init(interp_, x_start, y_start, size_); // linear model for extrapolation: TransformationModel::DataPoints lm_data(2); lm_data[0] = make_pair(x_[0], y_[0]); lm_data[1] = make_pair(x_[size_ - 1], y_[size_ - 1]); lm_ = new TransformationModelLinear(lm_data, Param()); }
UNUSED static REAL8 XLALSimInspiralNRWaveformGetRefTimeFromRefFreq( UNUSED LALH5File* file, UNUSED REAL8 fRef ) { #ifndef LAL_HDF5_ENABLED XLAL_ERROR(XLAL_EFAILED, "HDF5 support not enabled"); #else /* NOTE: This is an internal function, it is expected that fRef is scaled * to correspond to the fRef with a total mass of 1 solar mass */ LALH5File *curr_group = NULL; gsl_vector *omega_t_vec = NULL; gsl_vector *omega_w_vec = NULL; gsl_interp_accel *acc; gsl_spline *spline; REAL8 ref_time; curr_group = XLALH5GroupOpen(file, "Omega-vs-time"); ReadHDF5RealVectorDataset(curr_group, "X", &omega_t_vec); ReadHDF5RealVectorDataset(curr_group, "Y", &omega_w_vec); acc = gsl_interp_accel_alloc(); spline = gsl_spline_alloc(gsl_interp_cspline, omega_w_vec->size); gsl_spline_init(spline, omega_w_vec->data, omega_t_vec->data, omega_t_vec->size); ref_time = gsl_spline_eval(spline, fRef * (LAL_MTSUN_SI * LAL_PI), acc); gsl_vector_free(omega_t_vec); gsl_vector_free(omega_w_vec); gsl_spline_free(spline); gsl_interp_accel_free(acc); return ref_time; #endif }
/// Power spectra numerical implementation. Initializing spline. void cosmology::init_powerspectra_L() { if(verbose){ std::cout<<"# "<<"============================================================="<<std::endl; std::cout<<"# "<<"The spline for linear power spectra was not initialized. Initializing..."<<std::endl; } //Define the limits for which to calculate the variance double xx[Npower],yy[Npower]; for (int i=0;i<Npower;i++) { double k=kmin+i/(Npower-1.)*(kmax-kmin); xx[i]=k; k=pow(10.0,k); /// Improvement possible here yy[i]=log10(Delta2_L(k,0.0)); } PSL0_acc = gsl_interp_accel_alloc (); PSL0_spline = gsl_spline_alloc (gsl_interp_cspline, Npower); gsl_spline_init (PSL0_spline,xx,yy,Npower); PSL0_dlow=(yy[2]-yy[0])/(xx[2]-xx[0]); PSL0_xlow=xx[1]; PSL0_ylow=yy[1]; PSL0_dhigh=(yy[Npower-3]-yy[Npower-1])/(xx[Npower-3]-xx[Npower-1]); PSL0_xhigh=xx[Npower-2]; PSL0_yhigh=yy[Npower-2]; bool_init_PSL0=true; if(verbose){ std::cout<<"# "<<"The spline for numerical calculation of linear power spectra is now initialized"<<std::endl; std::cout<<"# "<<"============================================================="<<std::endl; } }
double calc_corr_at_R(double R,double*k,double*P,int Nk,int N,double h){ double zero,psi,x,t,dpsi,f,PIsinht; double PI_h = PI/h; double PI_2 = PI*0.5; gsl_spline*Pspl = gsl_spline_alloc(gsl_interp_cspline,Nk); gsl_spline_init(Pspl,k,P,Nk); gsl_interp_accel*acc= gsl_interp_accel_alloc(); double sum = 0; int i; for(i=0;i<N;i++){ zero = i+1; psi = h*zero*tanh(sinh(h*zero)*PI_2); x = psi*PI_h; t = h*zero; PIsinht = PI*sinh(t); dpsi = (PI*t*cosh(t)+sinh(PIsinht))/(1+cosh(PIsinht)); if (dpsi!=dpsi) dpsi=1.0; f = x*get_P(x,R,k,P,Nk,Pspl,acc); sum += f*sin(x)*dpsi; } gsl_spline_free(Pspl),gsl_interp_accel_free(acc); return sum/(R*R*R*PI*2); }
int main (void) { int N = 4; double x[4] = {0.00, 0.10, 0.27, 0.30}; double y[4] = {0.15, 0.70, -0.10, 0.15}; /* Note: first = last for periodic data */ gsl_interp_accel *acc = gsl_interp_accel_alloc (); const gsl_interp_type *t = gsl_interp_cspline_periodic; gsl_spline *spline = gsl_spline_alloc (t, N); int i; double xi, yi; printf ("#m=0,S=5\n"); for (i = 0; i < N; i++) { printf ("%g %g\n", x[i], y[i]); } printf ("#m=1,S=0\n"); gsl_spline_init (spline, x, y, N); for (i = 0; i <= 100; i++) { xi = (1 - i / 100.0) * x[0] + (i / 100.0) * x[N-1]; yi = gsl_spline_eval (spline, xi, acc); printf ("%g %g\n", xi, yi); } gsl_spline_free (spline); gsl_interp_accel_free (acc); return 0; }
/// Initialize the spline for numerically calculating the variance /// This is valid for redshift z=0.0. Should be appropriately multiplied by the /// growth factor to extend to redshift z. void cosmology::init_varM_TH_spline() { if(verbose){ std::cout<<"# "<<"============================================================="<<std::endl; std::cout<<"# "<<"The spline for numerical calculation of variance was not initialized. Initializing..."<<std::endl; } //Define the limits for which to calculate the variance double mmin=5.0; double mmax=18.0; double xx[Nsigma],yy[Nsigma]; for (int i=0;i<Nsigma;i++) { double m=mmin+i/(Nsigma-1.)*(mmax-mmin); xx[i]=m; m=pow(10.,m); yy[i]=log(varM_TH(m,0.0))/log(10.); //std::cout<<xx[i]<<" "<<yy[i]<<std::endl; } varM_TH_num_acc = gsl_interp_accel_alloc (); varM_TH_num_spline = gsl_spline_alloc (gsl_interp_cspline, Nsigma); gsl_spline_init (varM_TH_num_spline,xx,yy,Nsigma); bool_init_varM_TH_spline=true; if(verbose){ std::cout<<"# "<<"The spline for numerical calculation of variance is now initialized"<<std::endl; std::cout<<"# "<<"============================================================="<<std::endl; } }
static void init_interp(struct disp_sample_table *dt) { dt->interp_n = gsl_interp_alloc(gsl_interp_cspline, dt->len); dt->interp_k = gsl_interp_alloc(gsl_interp_cspline, dt->len); dt->accel = gsl_interp_accel_alloc(); }
void regrid_sed(double z,double *plam,double *pval,long finelength, \ long sedlength,double *fineplam,double *finepval) { long ii; double x[sedlength],y[sedlength]; for (ii=0;ii<sedlength;ii++) { x[ii] = *(plam+ii) * (1.0 + z); y[ii] = *(pval+ii); } gsl_interp_accel *acc = gsl_interp_accel_alloc(); gsl_spline *spline = gsl_spline_alloc(gsl_interp_cspline, sedlength); gsl_spline_init(spline, x, y, sedlength); for (ii=0; ii < finelength; ii++) { if (*(fineplam+ii)/(1.0 + z) < *(plam+0)) { *(finepval+ii) = 0.0; } else { *(finepval+ii) = gsl_spline_eval (spline, *(fineplam+ii), acc); } if (*(finepval+ii) < 0.0) *(finepval+ii) = 0.0; } gsl_spline_free(spline); gsl_interp_accel_free(acc); }
void Interpolation::calculateOutputData(double *x, double *y) { gsl_interp_accel *acc = gsl_interp_accel_alloc (); const gsl_interp_type *method; switch(d_method) { case 0: method = gsl_interp_linear; break; case 1: method = gsl_interp_cspline; break; case 2: method = gsl_interp_akima; break; } gsl_spline *interp = gsl_spline_alloc (method, d_n); gsl_spline_init (interp, d_x, d_y, d_n); double step = (d_to - d_from)/(double)(d_points - 1); for (int j = 0; j < d_points; j++) { x[j] = d_from + j*step; y[j] = gsl_spline_eval (interp, x[j], acc); } gsl_spline_free (interp); gsl_interp_accel_free (acc); }
void smoothing_integrate(smoothing_params ¶ms, 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 = ¶ms; 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); }
/** * The function fills the flux information from a point in * a fluxcube structure into the flux part of a direct object. * * @param fcube - the fluxcube structure * @param point - the position to take the flux from * @param actdir - the direct object to update * */ void fill_fluxvalues(const flux_cube *fcube, const px_point point, dirobject *actdir, const int inter_type) { energy_distrib *sed; double *sed_wavs; double *sed_flux; int i; int iact; sed = (energy_distrib*) malloc(sizeof(energy_distrib)); sed_wavs = (double*) malloc(fcube->n_fimage*sizeof(double)); sed_flux = (double*) malloc(fcube->n_fimage*sizeof(double)); if (actdir->SED) free_enerdist (actdir->SED); // go over each fluximage in the fluxcube structure for (i=0; i < fcube->n_fimage; i++) { // determine the index of the next fluximage iact = gsl_vector_int_get(fcube->fimage_order, i); // transfer the wavelength and flux from the fluxcube sed_wavs[i] = fcube->fluxims[iact]->wavelength; sed_flux[i] = gsl_matrix_get(fcube->fluxims[iact]->flux, point.x, point.y); } sed->npoints = fcube->n_fimage; sed->wavelength = sed_wavs ; sed->flux = sed_flux; if (fcube->n_fimage > 1) { if (inter_type == 2) sed->interp = gsl_interp_alloc (gsl_interp_polynomial, (size_t)fcube->n_fimage); else if (inter_type == 3) sed->interp = gsl_interp_alloc (gsl_interp_cspline, (size_t)fcube->n_fimage); else sed->interp = gsl_interp_alloc (gsl_interp_linear, (size_t)fcube->n_fimage); sed->accel = gsl_interp_accel_alloc (); gsl_interp_init (sed->interp, sed->wavelength, sed->flux, (size_t)sed->npoints); } else { sed->interp = NULL; sed->accel= NULL; } // transfer the SED; // announce the SED actdir->SED = sed; actdir->bb_sed = 1; }
UNUSED static UINT4 XLALSimInspiralNRWaveformGetDataFromHDF5File( UNUSED REAL8Vector** output, /**< Returned vector uncompressed */ UNUSED LALH5File* pointer, /**< Pointer to HDF5 file */ UNUSED REAL8 totalMass, /**< Total mass of system for scaling */ UNUSED REAL8 startTime, /**< Start time of veturn vector */ UNUSED size_t length, /**< Length of returned vector */ UNUSED REAL8 deltaT, /**< Sample rate of returned vector */ UNUSED const char *keyName /**< Name of vector to uncompress */ ) { #ifndef LAL_HDF5_ENABLED XLAL_ERROR(XLAL_EFAILED, "HDF5 support not enabled"); #else UINT4 idx; size_t comp_data_length; REAL8 massTime; gsl_interp_accel *acc; gsl_spline *spline; gsl_vector *knotsVector, *dataVector; LALH5File *group = XLALH5GroupOpen(pointer, keyName); knotsVector=dataVector=NULL; ReadHDF5RealVectorDataset(group, "X", &knotsVector); ReadHDF5RealVectorDataset(group, "Y", &dataVector); *output = XLALCreateREAL8Vector(length); comp_data_length = dataVector->size; /* SPLINE STUFF */ acc = gsl_interp_accel_alloc(); spline = gsl_spline_alloc(gsl_interp_cspline, comp_data_length); gsl_spline_init(spline, knotsVector->data, dataVector->data, comp_data_length); for (idx = 0; idx < length; idx++) { massTime = (startTime + idx*deltaT) / (totalMass * LAL_MTSUN_SI); /* This if statement is used to catch the case where massTime at idx=0 * ends up at double precision smaller than the first point in the * interpolation. In this case set it back to exactly the first point. * Sanity checking that we are not trying to use data below the * interpolation range is done elsewhere. */ if ((idx == 0) && (massTime < knotsVector->data[0])) { massTime = knotsVector->data[0]; } (*output)->data[idx] = gsl_spline_eval(spline, massTime, acc); } gsl_vector_free(knotsVector); gsl_vector_free(dataVector); gsl_spline_free (spline); gsl_interp_accel_free (acc); return XLAL_SUCCESS; #endif }
void compute_correlation_func(int ObsNr, double *binsamdata, int snap, float mingalmass, float maxgalmass) { double *r,*proj,*r_tmp,*proj_tmp; int ibin, ii, jj; char buf[1000]; FILE *fa; gsl_spline *Proj_Spline; gsl_interp_accel *Proj_SplineAcc; NR=60; //printf("\ncalculating correlation function %0.2f < M < %0.2f\n",mingalmass,maxgalmass); r=malloc(NR*sizeof(double)); proj=malloc(NR*sizeof(double)); halomodel(r,proj,mingalmass,maxgalmass,snap); Proj_Spline=gsl_spline_alloc(gsl_interp_cspline,NR); Proj_SplineAcc=gsl_interp_accel_alloc(); gsl_spline_init(Proj_Spline,r,proj,NR); //for(ii=0;ii<Nbins[snap][ObsNr]-1;ii++) // printf("Nbins=%d r=%g\n",Nbins[snap][ObsNr], MCMC_Obs[ObsNr].Bin_low[snap][ii]+(MCMC_Obs[ObsNr].Bin_high[snap][ii]-MCMC_Obs[ObsNr].Bin_low[snap][ii])/2.) for(ii=0;ii<Nbins[snap][ObsNr]-1;ii++) binsamdata[ii]=gsl_spline_eval(Proj_Spline,MCMC_Obs[ObsNr].Bin_low[snap][ii]+(MCMC_Obs[ObsNr].Bin_high[snap][ii]-MCMC_Obs[ObsNr].Bin_low[snap][ii])/2.,Proj_SplineAcc); #ifndef PARALLEL //full3 - full PLANCK sprintf(buf, "%s/correlation_guo10_bug_fix_full_z0.02_%0.2f_%0.2f.txt",OutputDir, mingalmass,maxgalmass); if(!(fa = fopen(buf, "w"))) { char sbuf[1000]; sprintf(sbuf, "can't open file `%s'\n", buf); terminate(sbuf); } for(ii=0;ii<Nbins[snap][ObsNr]-1;ii++) fprintf(fa, "%g %g %g\n", MCMC_Obs[ObsNr].Bin_low[snap][ii]+(MCMC_Obs[ObsNr].Bin_high[snap][ii]-MCMC_Obs[ObsNr].Bin_low[snap][ii])/2.,binsamdata[ii],binsamdata[ii]*0.1); //for(ii=0;ii<NR;ii++) //fprintf(fa, "%g %g %g\n", r[ii],proj[ii],proj[ii]*0.1); fclose(fa); #endif //original wrp calculation out of halo_model //printf("\n\n %g<M<%g",mingalmass,maxgalmass); //for(ii=0;ii<NR;ii++) // printf("r=%g proj=%g\n",r[ii],proj[ii]); //interpolated into obs bins //for(ii=0;ii<Nbins[snap][ObsNr]-1;ii++) // printf("%g %g %g\n", MCMC_Obs[ObsNr].Bin_low[snap][ii]+(MCMC_Obs[ObsNr].Bin_high[snap][ii]-MCMC_Obs[ObsNr].Bin_low[snap][ii])/2.,binsamdata[ii],binsamdata[ii]*0.1); free(r); free(proj); gsl_spline_free(Proj_Spline); gsl_interp_accel_free(Proj_SplineAcc); }