LALSimulation  5.4.0.1-fe68b98
LALSimIMRSpinPrecEOBGSLOptimizedInterpolation.c
Go to the documentation of this file.
1 #ifndef _LALSIMIMRSPINPRECEOBGSLOPTIMIZEDINTERPOLATION_C
2 #define _LALSIMIMRSPINPRECEOBGSLOPTIMIZEDINTERPOLATION_C
3 
5 
6 /*------------------------------------------------------------------------------------------
7  *
8  * Definitions of functions (only one in this file, so no prototypes needed).
9  *
10  *------------------------------------------------------------------------------------------
11  */
13  REAL8 * yin, /**<< Data to be interpolated; time first */
14  REAL8 tinit, /**<< time at which to begin interpolating */
15  REAL8 deltat, /**<< Spacing between interpolated times */
16  UINT4 num_input_times, /**<< The number of input times */
17  REAL8Array ** yout, /**<< Interpolation output */
18  size_t dim /**<< Number of quantities interpolated (e.g. if yin = {t,x,y,z} then dim 3) */
19  )
20 {
21  int errnum = 0;
22 
23  /* needed for the final interpolation */
24  gsl_spline *interp = NULL;
25  gsl_interp_accel *accel = NULL;
26  int outputlen = 0;
27  REAL8Array *output = NULL;
28  REAL8 *times, *vector; /* aliases */
29 
30  /* note: for speed, this replaces the single CALLGSL wrapper applied before each GSL call */
31  interp = gsl_spline_alloc(gsl_interp_cspline, num_input_times);
32  accel = gsl_interp_accel_alloc();
33 
34  outputlen = (int)(yin[num_input_times-1] / deltat) + 1;
35 
36  output = XLALCreateREAL8ArrayL(2, dim+1, outputlen);/* Original (dim+1)*/
37 
38  if (!interp || !accel || !output) {
39  errnum = XLAL_ENOMEM; /* ouch again, ran out of memory */
40  if (output)
42  outputlen = 0;
43  goto bail_out;
44  }
45 
46  /* make an array of times */
47  times = output->data;
48  for (int j = 0; j < outputlen; j++)
49  times[j] = tinit + deltat * j;
50 
51  /* interpolate! */
52  for (unsigned int i = 1; i <= dim; i++) { /* Original (dim) */
53  //gsl_spline_init(interp, &yin->data[0], &yin->data[num_input_times * i], num_input_times + 1);
54  gsl_spline_init(interp, yin, &(yin[num_input_times * i]), num_input_times);
55 
56  vector = output->data + outputlen * i;
57  unsigned int index_old=0;
58  double x_lo_old=0,y_lo_old=0,b_i_old=0,c_i_old=0,d_i_old=0;
59  for (int j = 0; j < outputlen; j++) {
60  optimized_gsl_spline_eval_e(interp,times[j],accel, &(vector[j]),&index_old,&x_lo_old,&y_lo_old,&b_i_old,&c_i_old,&d_i_old);
61  }
62  }
63 
64  /* deallocate stuff and return */
65  bail_out:
66 
67  if (interp)
68  XLAL_CALLGSL(gsl_spline_free(interp));
69  if (accel)
70  XLAL_CALLGSL(gsl_interp_accel_free(accel));
71 
72  if (errnum)
73  XLAL_ERROR(errnum);
74 
75  *yout = output;
76  return outputlen;
77 }
78 
79 #endif // _LALSIMIMRSPINPRECEOBGSLOPTIMIZEDINTERPOLATION_C
static int optimized_gsl_spline_eval_e(const gsl_spline *spline, double interptime, gsl_interp_accel *accel, double *output, unsigned int *index_old, double *x_lo_old, double *y_lo_old, double *b_i_old, double *c_i_old, double *d_i_old)
Perform cubic spline interpolation to achieve evenly-sampled data from that input data.
static int SEOBNRv3OptimizedInterpolatorGeneral(REAL8 *yin, REAL8 tinit, REAL8 deltat, UINT4 num_input_times, REAL8Array **yout, size_t dim)
#define XLAL_CALLGSL(statement)
double i
Definition: bh_ringdown.c:118
REAL8Array * XLALCreateREAL8ArrayL(UINT4,...)
void XLALDestroyREAL8Array(REAL8Array *)
double REAL8
uint32_t UINT4
#define XLAL_ERROR(...)
XLAL_ENOMEM
char output[FILENAME_MAX]
Definition: unicorn.c:26