コード例 #1
0
ファイル: CubicSpline.cpp プロジェクト: mkoennecke/mantid
/**Evaluate a point on the spline. Includes basic error handling
 *
 * @param x :: Point to evaluate
 * @return :: the value of the spline at the given point
 */
double CubicSpline::splineEval(const double x) const {
  // calculate the y value
  double y = gsl_spline_eval(m_spline.get(), x, m_acc.get());
  int errorCode = gsl_spline_eval_e(m_spline.get(), x, m_acc.get(), &y);

  // check if GSL function returned an error
  checkGSLError(errorCode, GSL_EDOM);

  return y;
}
コード例 #2
0
ファイル: random.c プロジェクト: flaviasobreira/CUTE
static double num_dens_z(double rsh)
{
  //////
  // Returns N(z=rsh)
  double result;

  if((rsh<=redshift_0)||(rsh>=redshift_f)) 
    result=0;
  else
    gsl_spline_eval_e(cute_spline_dndz,rsh,cute_intacc_dndz,&result);
  
  return result;
}
コード例 #3
0
ファイル: Particles.C プロジェクト: cdeil/GAMERA
/** Determine the maximum energy of particles between tmin and Age.
 * This energy is then used as upper boundary for the energy dimension of the
 * grid.
 */
double Particles::DetermineEmax(double tmin) {
  double t = 0.;
  double dt = 0.;
  double tt = 0.;
  double eMaxHistory = -1.;
  t = tmin;
  dt = (Age - tmin) / 10000.;
  while (t <= Age) {
    if (gsl_spline_eval_e(eMaxLookup, t, acceMax, &tt)) continue;
    if (tt > eMaxHistory) eMaxHistory = tt;
    t += dt;
  }
  return eMaxHistory;
}
コード例 #4
0
ファイル: spline.c プロジェクト: Fudge/rb-gsl
static VALUE rb_gsl_spline_eval_e(VALUE obj, VALUE xx)
{
  rb_gsl_spline *rgs = NULL;
  double val;
  int status;
  Data_Get_Struct(obj, rb_gsl_spline, rgs);
  Need_Float(xx);
  status = gsl_spline_eval_e(rgs->s, NUM2DBL(xx), rgs->a, &val);
  switch (status) {
  case GSL_EDOM:
    rb_gsl_error_handler("gsl_spline_eval_e error", __FILE__, __LINE__, status);
    break;
  default:
    return rb_float_new(val);
    break;
  }
  return Qnil;
}
コード例 #5
0
ファイル: Particles.C プロジェクト: cdeil/GAMERA
/** 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;
}
コード例 #6
0
/**
 * Function which calculates the value of the waveform, plus its
 * first and second derivatives, for the points which will be required
 * in the hybrid comb attachment of the ringdown.
 */
static INT4 XLALGenerateHybridWaveDerivatives (
	REAL8Vector	*rwave,      /**<< OUTPUT, values of the waveform at comb points */
	REAL8Vector	*dwave,      /**<< OUTPUT, 1st deriv of the waveform at comb points */
	REAL8Vector	*ddwave,     /**<< OUTPUT, 2nd deriv of the waveform at comb points */
        REAL8Vector	*timeVec,    /**<< Vector containing the time */
	REAL8Vector	*wave,       /**<< Last part of inspiral waveform */
	REAL8Vector	*matchrange, /**<< Times which determine the size of the comb */
        REAL8           dt,          /**<< Sample time step */
        REAL8           mass1,       /**<< First component mass (in Solar masses) */
        REAL8           mass2        /**<< Second component mass (in Solar masses) */
	)
{

  /* XLAL error handling */
  INT4 errcode = XLAL_SUCCESS;

  /* For checking GSL return codes */
  INT4 gslStatus;

  UINT4 j;
  UINT4 vecLength;
  REAL8 m;
  double *y;
  double ry, dy, dy2;
  double rt;
  double *tlist;
  gsl_interp_accel *acc;
  gsl_spline *spline;

  /* Total mass in geometric units */
  m  = (mass1 + mass2) * LAL_MTSUN_SI;

  tlist = (double *) LALMalloc(6 * sizeof(double));
  rt = (matchrange->data[1] - matchrange->data[0]) / 5.;
  tlist[0] = matchrange->data[0];
  tlist[1] = tlist[0] + rt;
  tlist[2] = tlist[1] + rt;
  tlist[3] = tlist[2] + rt;
  tlist[4] = tlist[3] + rt;
  tlist[5] = matchrange->data[1];

  /* Set the length of the interpolation vectors */
  vecLength = ( m * matchrange->data[2] / dt ) + 1;

  /* Getting interpolation and derivatives of the waveform using gsl spline routine */
  /* Initiate arrays and supporting variables for gsl */
  y = (double *) LALMalloc(vecLength * sizeof(double));

  if ( !y )
  {
    XLAL_ERROR( XLAL_ENOMEM );
  }

  for (j = 0; j < vecLength; ++j)
  {
	y[j] = wave->data[j];
  }


  XLAL_CALLGSL( acc = (gsl_interp_accel*) gsl_interp_accel_alloc() );
  XLAL_CALLGSL( spline = (gsl_spline*) gsl_spline_alloc(gsl_interp_cspline, vecLength) );
  if ( !acc || !spline )
  {
    if ( acc )    gsl_interp_accel_free(acc);
    if ( spline ) gsl_spline_free(spline);
    LALFree( y );
    XLAL_ERROR( XLAL_ENOMEM );
  }

  /* Gall gsl spline interpolation */
  gslStatus = gsl_spline_init(spline, timeVec->data, y, vecLength);
  if ( gslStatus != GSL_SUCCESS )
  { 
    gsl_spline_free(spline);
    gsl_interp_accel_free(acc);
    LALFree( y );
    XLAL_ERROR( XLAL_EFUNC );
  }

  /* Getting first and second order time derivatives from gsl interpolations */
  for (j = 0; j < 6; ++j)
  {
    gslStatus = gsl_spline_eval_e( spline, tlist[j], acc, &ry );
    if ( gslStatus == GSL_SUCCESS )
    {
      gslStatus = gsl_spline_eval_deriv_e(spline, tlist[j], acc, &dy );
      gslStatus = gsl_spline_eval_deriv2_e(spline, tlist[j], acc, &dy2 );
    }
    if (gslStatus != GSL_SUCCESS )
    {
      gsl_spline_free(spline);
      gsl_interp_accel_free(acc);
      LALFree( y );
      XLAL_ERROR( XLAL_EFUNC );
    }
    rwave->data[j]  = (REAL8)(ry);
    dwave->data[j]  = (REAL8)(dy/m);
    ddwave->data[j] = (REAL8)(dy2/m/m);

  }
  
  /* Free gsl variables */
  gsl_spline_free(spline);
  gsl_interp_accel_free(acc);
  LALFree( tlist );
  LALFree(y);

  return errcode;
}