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 }
bool CustomNonlinearProperty::setData(const QModelIndex &index, const QVariant &value, int role) { if(index.parent() != QModelIndex() && role != Qt::EditRole) { return false; } bool b; const double d = value.toDouble(&b); if (b) { switch (index.column()) { case StrainColumn: m_strain[index.row()] = d; break; case PropertyColumn: m_average[index.row()] = d; m_varied[index.row()] = d; gsl_interp_accel_reset(m_acc); break; } dataChanged(index, index); return true; } else { return false; } }
// ----------------------------------------------------------------------------- void hand_anim_chg(int p, double x, double y) { DEBUGLOGB; if( p >= 0 && p < g_curvePtsN ) { g_curvePtsX[p] = x; g_curvePtsY[p] = y; #ifdef _USEGSL #ifdef _USEGSL_STATIC if( g_curveTerp ) gsl_interp_init(g_curveTerp, g_curvePtsX, g_curvePtsY, g_curvePtsN); if( g_curveAccl ) gsl_interp_accel_reset(g_curveAccl); #else // _USEGSL_STATIC if( g_pLLibok ) { if( g_curveTerp ) g_gsl_interp_init(g_curveTerp, g_curvePtsX, g_curvePtsY, g_curvePtsN); if( g_curveAccl ) g_gsl_interp_accel_reset(g_curveAccl); } else { g_curvePtsS[0] = 0; for( int i = 1; i < g_curvePtsN; i++ ) { g_curvePtsS[i] = (g_curvePtsY[i] - g_curvePtsY[i-1])/(g_curvePtsX[i] - g_curvePtsX[i-1]); } } #endif // _USEGSL_STATIC #else // _USEGSL #ifdef _USESPLINE csp::set_points(g_curve, g_curvePtsX, g_curvePtsY, g_curvePtsN); #else g_curvePtsS[0] = 0; for( int i = 1; i < g_curvePtsN; i++ ) { g_curvePtsS[i] = (g_curvePtsY[i] - g_curvePtsY[i-1])/(g_curvePtsX[i] - g_curvePtsX[i-1]); } #endif // _USESPLINE #endif // _USEGSL } DEBUGLOGE; }
void NonlinearProperty::initialize() { if (m_strain.size() > 2) { if (m_interp) gsl_interp_free(m_interp); m_interp = gsl_interp_alloc(gsl_interp_cspline, m_strain.size()); gsl_interp_init(m_interp, m_strain.data(), m_varied.data(), m_strain.size()); gsl_interp_accel_reset(m_acc); } }
double transfer_function(double k) { static int initFlag = 1; static int currCosmoNum; static gsl_spline *cosmocalc_transfer_function_spline = NULL; static gsl_interp_accel *cosmocalc_transfer_function_acc = NULL; static double c0,c1; double transfer_function_table[COSMOCALC_TRANSFER_FUNCTION_TABLE_LENGTH]; double k_table[COSMOCALC_TRANSFER_FUNCTION_TABLE_LENGTH]; long i; double cov00,cov01,cov11,sumsq; if(initFlag == 1 || currCosmoNum != cosmoData.cosmoNum) { initFlag = 0; currCosmoNum = cosmoData.cosmoNum; for(i=0;i<COSMOCALC_TRANSFER_FUNCTION_TABLE_LENGTH;++i) { k_table[i] = log(K_MAX/K_MIN)/(COSMOCALC_TRANSFER_FUNCTION_TABLE_LENGTH-1.0)*((double) i) + log(K_MIN); if(cosmoData.useSmoothTransFunc) transfer_function_table[i] = log(transfunct_eh98_smooth(exp(k_table[i]))); else if(cosmoData.useNoTransFunc) transfer_function_table[i] = 0.0; else transfer_function_table[i] = log(transfunct_eh98(exp(k_table[i]))); } //init the spline and accelerators if(cosmocalc_transfer_function_spline != NULL) gsl_spline_free(cosmocalc_transfer_function_spline); cosmocalc_transfer_function_spline = gsl_spline_alloc(GSL_SPLINE_TYPE,(size_t) (COSMOCALC_TRANSFER_FUNCTION_TABLE_LENGTH)); gsl_spline_init(cosmocalc_transfer_function_spline,k_table,transfer_function_table,(size_t) (COSMOCALC_TRANSFER_FUNCTION_TABLE_LENGTH)); if(cosmocalc_transfer_function_acc != NULL) gsl_interp_accel_reset(cosmocalc_transfer_function_acc); else cosmocalc_transfer_function_acc = gsl_interp_accel_alloc(); gsl_fit_linear(k_table+COSMOCALC_TRANSFER_FUNCTION_TABLE_LENGTH-COSMOCALC_TRANSFER_FUNCTION_FIT_LENGTH,(size_t) 1, transfer_function_table+COSMOCALC_TRANSFER_FUNCTION_TABLE_LENGTH-COSMOCALC_TRANSFER_FUNCTION_FIT_LENGTH,(size_t) 1, (size_t) COSMOCALC_TRANSFER_FUNCTION_FIT_LENGTH,&c0,&c1,&cov00,&cov01,&cov11,&sumsq); } if(k < K_MIN) return 1.0; else if(k < K_MAX) return exp(gsl_spline_eval(cosmocalc_transfer_function_spline,log(k),cosmocalc_transfer_function_acc)); else return exp(c0+c1*log(k)); }
/** determine the minimum time from where to start * the calculation. Electrons before that time are injected as * a single 'blob'. This time is derived from the requirement * that the blob has slid down to energies e.g. E<1GeV(EMIN) at t=Age. */ void Particles::DetermineTMin(double emin, double &tmin) { double logt, logtmin, logtmax, logdt, logsteps, TMIN; if (TminInternal > 0.) logtmin = log10(TminInternal); else logtmin = log10(Age) - 5.; TMIN = 0.; logtmax = log10(Age); if (logtmin > logtmax) logtmin = logtmax - 3.; logsteps = 30.; logdt = (logtmax - logtmin) / logsteps; for (logt = logtmin; logt < logtmax; logt += logdt) { CalculateEnergyTrajectory(pow(10., logt)); gsl_interp_accel_reset(accTrInv); if (gsl_spline_eval_e(energyTrajectoryInverse, log10(emin), accTrInv, &TMIN)) continue; TMIN = pow(10., TMIN); if (TMIN > Age) break; tmin = pow(10., logt); } return; }
static int bicubic_init(void * vstate, const double xa[], const double ya[], const double za[], size_t xsize, size_t ysize) { bicubic_state_t *state = (bicubic_state_t *) vstate; gsl_interp_accel *acc = gsl_interp_accel_alloc(); gsl_spline *spline; gsl_vector *x; gsl_vector *y; size_t i, j; x = gsl_vector_alloc(xsize); y = gsl_vector_alloc(xsize); spline = gsl_spline_alloc(gsl_interp_cspline, xsize); for (j = 0; j <= ysize - 1; j++) { for (i = 0; i <= xsize - 1; i++) { gsl_vector_set(x, i, xa[i]); gsl_vector_set(y, i, za[IDX2D(i, j, state)]); } gsl_spline_init(spline, x->data, y->data, xsize); for (i = 0; i <= xsize - 1; i++) { state->zx[IDX2D(i, j, state)] = gsl_spline_eval_deriv(spline, xa[i], acc); } } gsl_vector_free(x); gsl_vector_free(y); gsl_spline_free(spline); gsl_interp_accel_reset(acc); x = gsl_vector_alloc(ysize); y = gsl_vector_alloc(ysize); spline = gsl_spline_alloc(gsl_interp_cspline, ysize); for (i = 0; i <= xsize - 1; i++) { for (j = 0; j <= ysize - 1; j++) { gsl_vector_set(x, j, ya[j]); gsl_vector_set(y, j, za[IDX2D(i, j, state)]); } gsl_spline_init(spline, x->data, y->data, ysize); for (j = 0; j <= ysize - 1; j++) { state->zy[IDX2D(i, j, state)] = gsl_spline_eval_deriv(spline, ya[j], acc); } } gsl_vector_free(x); gsl_vector_free(y); gsl_spline_free(spline); gsl_interp_accel_reset(acc); x = gsl_vector_alloc(xsize); y = gsl_vector_alloc(xsize); spline = gsl_spline_alloc(gsl_interp_cspline, xsize); for (j = 0; j <= ysize - 1; j++) { for (i = 0; i <= xsize - 1; i++) { gsl_vector_set(x, i, xa[i]); gsl_vector_set(y, i, state->zy[IDX2D(i, j, state)]); } gsl_spline_init(spline, x->data, y->data, xsize); for (i = 0; i <= xsize - 1; i++) { state->zxy[IDX2D(i, j, state)] = gsl_spline_eval_deriv(spline, xa[i], acc); } } gsl_vector_free(x); gsl_vector_free(y); gsl_spline_free(spline); gsl_interp_accel_free(acc); return GSL_SUCCESS; } /* bicubic_init() */
void gamma_spline_reset (GammaSpline *gs, GList * const sd, int mp, int np, gboolean sort) { int q=0; int NB = model->total_bands; int m,n; GList * iter = sd; const int N = g_list_length(iter); MatrixElement *firstme = (MatrixElement *) iter->data; size_t ind[NB]; if (sort) { gsl_sort_index (ind, firstme->energies, 1, NB); m=ind[mp]; n=ind[np]; // this breaks the 14 band model! } else { m=mp; n=np; } double *en = double_array_calloc(N); while (iter) { MatrixElement *me = (MatrixElement *) iter->data; gs->k[q]=me->kc; en[q]=(me->energies[n] - me->energies[m])*3e5/1240.7; gs->Wxr[q]=creal(me->Wx[m+n*NB]); gs->Wxi[q]=cimag(me->Wx[m+n*NB]); gs->Wyr[q]=creal(me->Wy[m+n*NB]); gs->Wyi[q]=cimag(me->Wy[m+n*NB]); gs->Wzr[q]=creal(me->Wz[m+n*NB]); gs->Wzi[q]=cimag(me->Wz[m+n*NB]); iter=g_list_next(iter); q++; } gsl_interp * en_spline; gsl_interp_accel * en_accel; en_spline = gsl_interp_alloc(gsl_interp_akima,N); en_accel = gsl_interp_accel_alloc(); q=gsl_interp_init(en_spline,gs->k,en,N); gsl_interp_accel_reset (en_accel); if (m!=n) { gs->phi[0]=0; for (q=1;q<N;q++) { gs->phi[q]=gs->phi[q-1]+2*M_PI*gsl_interp_eval_integ (en_spline, gs->k, en, gs->k[q-1], gs->k[q], en_accel); } } else { for (q=0;q<N;q++) { gs->phi[q]=0; } } d_free(en); gsl_interp_free(en_spline); gsl_interp_accel_free(en_accel); q=gsl_interp_init(gs->phi_spline,gs->k,gs->phi,N); gsl_interp_accel_reset (gs->phi_accel); q=gsl_interp_init(gs->wx_spline_re,gs->k,gs->Wxr,N); gsl_interp_accel_reset (gs->w_accel); q=gsl_interp_init(gs->wx_spline_im,gs->k,gs->Wxi,N); q=gsl_interp_init(gs->wy_spline_re,gs->k,gs->Wyr,N); q=gsl_interp_init(gs->wy_spline_im,gs->k,gs->Wyi,N); q=gsl_interp_init(gs->wz_spline_re,gs->k,gs->Wzr,N); q=gsl_interp_init(gs->wz_spline_im,gs->k,gs->Wzi,N); }
/** Reallocate the size of the GSL objects * * @param n :: The new size of the spline object */ void CubicSpline::reallocGSLObjects(const int n) { m_spline.reset(gsl_spline_alloc(gsl_interp_cspline, n),m_gslFree); gsl_interp_accel_reset (m_acc.get()); }
// ----------------------------------------------------------------------------- // ----------------------------------------------------------------------------- void hand_anim_set(const double* xs, const double* ys, int n) { DEBUGLOGB; DEBUGLOGP("xs is %s, ys is %s, n is %d\n", xs ? "valid" : "NOT valid", ys ? "valid" : "NOT valid", n); if( n > g_curvePtsM ) n = g_curvePtsM; g_curvePtsN = n; if( n && (xs || ys) ) { for( int i = 0; i < n; i++ ) { if( xs ) g_curvePtsX[i] = xs[i]; if( ys ) g_curvePtsY[i] = ys[i]; } #ifdef _USEGSL #ifdef _USEGSL_STATIC if( g_curveTerp ) { gsl_interp_free(g_curveTerp); g_curveTerp = NULL; } g_curveTerp = gsl_interp_alloc(g_curveType, g_curvePtsN); if( g_curveTerp ) gsl_interp_init(g_curveTerp, g_curvePtsX, g_curvePtsY, g_curvePtsN); if( g_curveAccl ) gsl_interp_accel_reset(g_curveAccl); #else // _USEGSL_STATIC if( g_pLLibok ) { if( g_curveTerp ) { g_gsl_interp_free(g_curveTerp); g_curveTerp = NULL; } g_curveTerp = g_gsl_interp_alloc(g_curveType, g_curvePtsN); if( g_curveTerp ) g_gsl_interp_init(g_curveTerp, g_curvePtsX, g_curvePtsY, g_curvePtsN); if( g_curveAccl ) g_gsl_interp_accel_reset(g_curveAccl); } else { g_curvePtsS[0] = 0; for( int i = 1; i < g_curvePtsN; i++ ) { g_curvePtsS[i] = (g_curvePtsY[i] - g_curvePtsY[i-1])/(g_curvePtsX[i] - g_curvePtsX[i-1]); } } #endif // _USEGSL_STATIC #else // _USEGSL #ifdef _USESPLINE csp::set_points(g_curve, g_curvePtsX, g_curvePtsY, g_curvePtsN); #else g_curvePtsS[0] = 0; for( int i = 1; i < g_curvePtsN; i++ ) { g_curvePtsS[i] = (g_curvePtsY[i] - g_curvePtsY[i-1])/(g_curvePtsX[i] - g_curvePtsX[i-1]); } #endif // _USESPLINE #endif // _USEGSL } DEBUGLOGE; }
static void comp_lens_corr_funcs(lensCorrFunc lcf) { #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 logttab[TABLE_LENGTH]; double logcfptab[TABLE_LENGTH]; double logcfmtab[TABLE_LENGTH]; int i; double lntmin; double lntmax; //init workspace = gsl_integration_workspace_alloc((size_t) WORKSPACE_NUM); F.params = lcf; lntmin = log(wlData.tmin); lntmax = log(wlData.tmax); //make tables F.function = &lenscfp_integrand; for(i=0;i<TABLE_LENGTH;++i) { logttab[i] = i*(lntmax-lntmin)/(TABLE_LENGTH-1) + lntmin; lcf->theta = exp(logttab[i]); gsl_integration_qag(&F,wlData.lmin,wlData.lmax,ABSERR,RELERR,(size_t) WORKSPACE_NUM,GSL_INTEG_GAUSS51,workspace,&result,&abserr); logcfptab[i] = log(result); } F.function = &lenscfm_integrand; for(i=0;i<TABLE_LENGTH;++i) { logttab[i] = i*(lntmax-lntmin)/(TABLE_LENGTH-1) + lntmin; lcf->theta = exp(logttab[i]); gsl_integration_qag(&F,wlData.lmin,wlData.lmax,ABSERR,RELERR,(size_t) WORKSPACE_NUM,GSL_INTEG_GAUSS51,workspace,&result,&abserr); logcfmtab[i] = log(result); } //free gsl_integration_workspace_free(workspace); //init splines and accels if(lcf->splineP != NULL) gsl_spline_free(lcf->splineP); lcf->splineP = gsl_spline_alloc(gsl_interp_akima,(size_t) (TABLE_LENGTH)); gsl_spline_init(lcf->splineP,logttab,logcfptab,(size_t) (TABLE_LENGTH)); if(lcf->accelP != NULL) gsl_interp_accel_reset(lcf->accelP); else lcf->accelP = gsl_interp_accel_alloc(); if(lcf->splineM != NULL) gsl_spline_free(lcf->splineM); lcf->splineM = gsl_spline_alloc(gsl_interp_akima,(size_t) (TABLE_LENGTH)); gsl_spline_init(lcf->splineM,logttab,logcfmtab,(size_t) (TABLE_LENGTH)); if(lcf->accelM != NULL) gsl_interp_accel_reset(lcf->accelM); else lcf->accelM = gsl_interp_accel_alloc(); #undef TABLE_LENGTH #undef ABSERR #undef RELERR #undef WORKSPACE_NUM }