LALSimulation  5.4.0.1-fe68b98
LALSimIMRSpinAlignedEOBOptimizedInterpolatorGeneral.c
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2010 Michele Vallisneri, Will Farr, Evan Ochsner, 2014 A. Klein
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with with program; see the file COPYING. If not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 * MA 02110-1301 USA
18 */
19 #ifndef _LALSIMIMRSPINALIGNEDEOBGSLOPTIMIZEDINTERPOLATORGENERAL_C
20 #define _LALSIMIMRSPINALIGNEDEOBGSLOPTIMIZEDINTERPOLATORGENERAL_C
21 
22 #include <stdio.h>
23 #include <math.h>
24 #include "stddef.h"
25 
26 #include <lal/LALSimInspiral.h>
27 #include <lal/LALSimIMR.h>
28 
29 #include "LALSimIMRSpinEOB.h"
30 
31 typedef struct
32 {
33  double * c;
34  double * g;
35  double * diag;
36  double * offdiag;
38 
39 /**
40  * Return the index ilo of x_array such that
41  * x_array[ilo] <= x < x_array[ilo+1]
42  * in the range [index_lo,index_hi].
43  */
44 static size_t optimized_gsl_interp_bsearch(const double x_array[], double x, size_t index_lo, size_t index_hi)
45 {
46  size_t ilo = index_lo;
47  size_t ihi = index_hi;
48  while(ihi > ilo + 1) {
49  size_t i = (ihi + ilo)/2;
50  if(x_array[i] > x)
51  ihi = i;
52  else
53  ilo = i;
54  }
55 
56  return ilo;
57 }
58 
59 /**
60  * Return the index cache of xa such that
61  * xa[cache] <= x < xa[cache+1].
62  */
63 static inline size_t optimized_gsl_interp_accel_find(gsl_interp_accel * a, const double xa[], size_t len, double x)
64 {
65  size_t x_index = a->cache;
66 
67  if(x < xa[x_index]) {
68  a->miss_count++;
69  a->cache = optimized_gsl_interp_bsearch(xa, x, 0, x_index);
70  }
71  else if(x >= xa[x_index + 1]) {
72  a->miss_count++;
73  a->cache = optimized_gsl_interp_bsearch(xa, x, x_index, len-1);
74  }
75  else {
76  a->hit_count++;
77  }
78  return a->cache;
79 }
80 
81 /**
82  * Return the coefficients of cubic spline interpolation between points
83  * c_array[index] and c_array[index+1].
84  */
85 static inline void optimized_coeff_calc (const double c_array[], double dy, double dx, size_t index, double * b, double * c, double * d)
86 {
87  const double c_i = c_array[index];
88  const double c_ip1 = c_array[index + 1];
89  *b = (dy / dx) - dx * (c_ip1 + 2.0 * c_i) / 3.0; //OPTIMIZED: It seems c_array is an array of derivatives
90  *c = c_i;
91  *d = (c_ip1 - c_i) / (3.0 * dx);
92 }
93 
94 /**
95  * Perform cubic spline interpolation at point x from data in x_array.
96  */
97 static int optimized_cspline_eval (const void * vstate, const double x_array[], const double y_array[], size_t size, double x, gsl_interp_accel * a, double *y,unsigned int *index_old, double *x_lo_old,double *y_lo_old,double *b_i_old,double *c_i_old,double *d_i_old)
98 {
99  const cspline_state_t *state = (const cspline_state_t *) vstate;
100 
101  double x_lo, x_hi;
102  double dx;
103  size_t index;
104 
105  index = optimized_gsl_interp_accel_find (a, x_array, size, x);
106  if(index==*index_old && (*index_old)>0) {
107  double delx = x - *x_lo_old;
108  *y = *y_lo_old + delx * (*b_i_old + delx * (*c_i_old + delx * *d_i_old));
109  } else {
110  /* evaluate */
111  x_hi = x_array[index + 1];
112  x_lo = x_array[index];
113  dx = x_hi - x_lo;
114  const double y_lo = y_array[index];
115  const double y_hi = y_array[index + 1];
116  const double dy = y_hi - y_lo;
117  double delx = x - x_lo;
118  double b_i, c_i, d_i;
119  optimized_coeff_calc(state->c, dy, dx, index, &b_i, &c_i, &d_i);//OPTIMIZED: It seems state->c is an array of derivatives at the indexed locations
120  *y = y_lo + delx * (b_i + delx * (c_i + delx * d_i));
121 
122  *b_i_old = b_i;
123  *c_i_old = c_i;
124  *d_i_old = d_i;
125  *x_lo_old = x_lo;
126  *y_lo_old = y_lo;
127  *index_old=index;
128  }
129 
130  return GSL_SUCCESS;
131 }
132 
133 /**
134  * Perform cubic spline interpolation to achieve evenly-sampled data from that
135  * input data.
136  */
137 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){
138  return optimized_cspline_eval(spline->interp->state, spline->x, spline->y, spline->interp->size, interptime, accel, output,index_old,x_lo_old,y_lo_old,b_i_old,c_i_old,d_i_old);
139 }
140 
141 #endif /* _LALSIMIMRSPINALIGNEDEOBGSLOPTIMIZEDINTERPOLATORGENERAL_C */
static size_t optimized_gsl_interp_bsearch(const double x_array[], double x, size_t index_lo, size_t index_hi)
Return the index ilo of x_array such that x_array[ilo] <= x < x_array[ilo+1] in the range [index_lo,...
static int optimized_cspline_eval(const void *vstate, const double x_array[], const double y_array[], size_t size, double x, gsl_interp_accel *a, double *y, 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 at point x from data in x_array.
static void optimized_coeff_calc(const double c_array[], double dy, double dx, size_t index, double *b, double *c, double *d)
Return the coefficients of cubic spline interpolation between points c_array[index] and c_array[index...
static size_t optimized_gsl_interp_accel_find(gsl_interp_accel *a, const double xa[], size_t len, double x)
Return the index cache of xa such that xa[cache] <= x < xa[cache+1].
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 vector d(const double L_norm, const double J_norm, const vector roots)
Internal function that returns the coefficients "d_0", "d_2" and "d_4" from 1703.03967 corresponding ...
#define c
double i
Definition: bh_ringdown.c:118
static const INT4 a
list x
list y
char output[FILENAME_MAX]
Definition: unicorn.c:26