Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
geodesics.cc
Go to the documentation of this file.
1 #include "geodesics.hh"
2 
3 #include "math.h"
4 #include "stdlib.h"
5 
6 //return values of f_util:
7 
8 static double r, pr, phi, tau, r2, a2, r3, Delta, R02, Q, A, B, r_dot, w, pr_dot, Edot, Ldot;
9 
10 // Here we compute second and third time derivatives of r and phi
11 // for a geodesic for use in the quadrupole formula
12 // REMOVED first three arguments! (made global)
13 
14 
15 void geo_higher_deriv(double E, double L, double a,
16  double& r_dotdot, double& r_dotdotdot, double& wdot, double& wdotdot)
17 {
18  // r2=r*r; a2=a*a; r3=r2*r;
19  // Delta=r2+a2-2*r; R02=r2+a2*(1+2/r); Q=Delta/(E*R02-2*a*L/r) // Q=tau_dot
20  // w=(L*Q+2*a/r)/R02 # w=phi_dot ; A=(w**2*(r3-a2)+2*a*w-1); B=(a2-r)/r3
21  // r_dot=Delta*Q*pr/r2
22  // pr_dot=A/r2/Q + B*pr**2*Q
23 
24  double F = r3+a2*r-2*r2;
25  double Fdot = (3*r2+a2-4*r)*r_dot;
26  double G = E*(r3+a2*r+2*a2)-2*a*L;
27  double Gdot = E*(3*r2+a2)*r_dot;
28  double Qdot = (Fdot*G-F*Gdot)/G/G;
29  double H = L*Q*r+2*a;
30  double Hdot = L*(Q*r_dot+Qdot*r);
31  double I = (r3+a2*r+2*a2);
32  double Idot = (3*r2+a2)*r_dot;
33  wdot = (Hdot*I-H*Idot)/I/I;
34  double Adot = 2*w*wdot*(r3-a2)+w*w*(3*r2*r_dot)+2*a*wdot;
35  double Bdot = (-3*a2/r2/r2+2/r3)*r_dot;
36  double C = r2+a2-2*r;
37  C *= C;
38  double Cdot = 4*(r-1)*(r2+a2-2*r)*r_dot;
39  double D = E*R02*r2-2*a*L*r;
40  double Ddot = E*(4*r3+2*a2*r)*r_dot+r_dot*(2*a2*E-2*a*L);
41  double alpha = Delta*Q/r2;
42  double alphadot = (Cdot*D-C*Ddot)/D/D;
43  r_dotdot = alphadot*pr + alpha*pr_dot;
44  double Cdotdot = 4*(r-1)*(r2+a2-2*r)*r_dotdot + 4*(r_dot)*(r2+a2-2*r)*r_dot
45  + 8*(r-1)*(r-1)*r_dot*r_dot;
46  double Ddotdot = E*(4*r3+2*a2*r)*r_dotdot+ E*(12*r2+2*a2)*r_dot*r_dot +
47  r_dotdot*(2*a2*E-2*a*L);
48  double alphadotdot = (Cdotdot*D-C*Ddotdot)/D/D - 2*(Cdot*D-C*Ddot)*Ddot/D/D/D;
49  double pr_dotdot = Adot/r2/Q-A*(2*r*r_dot*Q+r2*Qdot)/(r2*Q)/(r2*Q)+Bdot*pr*pr*Q
50  + 2*B*pr*pr_dot*Q+B*pr*pr*Qdot;
51  r_dotdotdot = alphadotdot*pr + 2*alphadot*pr_dot + alpha*pr_dotdot;
52  double Fdotdot = (3*r2+a2-4*r)*r_dotdot+(6*r-4)*r_dot*r_dot;
53  double Gdotdot = E*(3*r2+a2)*r_dotdot + E*6*r*r_dot*r_dot;
54  double Qdotdot = (Fdotdot*G-F*Gdotdot)/G/G-2*(Fdot*G-F*Gdot)*Gdot/G/G/G;
55  double Hdotdot = L*(Q*r_dotdot+Qdotdot*r+2*Qdot*r_dot);
56  double Idotdot = (3*r2+a2)*r_dotdot + 6*r*r_dot*r_dot;
57  wdotdot = (Hdotdot*I-H*Idotdot)/I/I-2*(Hdot*I-H*Idot)*Idot/I/I/I;
58 }
59 
60 
61 void reduced_quad_dot(double r, double r_t, double r_tt, double r_ttt, double phi,
62 double phi_t, double phi_tt, double phi_ttt, double (&I_tt)[3][3], double (&I_ttt)[3][3])
63 { double X = r*r;
64  double X_t = 2*r*r_t;
65  double X_tt = 2*r_t*r_t+2*r*r_tt;
66  double X_ttt = 6*r_t*r_tt+2*r*r_ttt;
67 
68  double cos2phi = cos(2*phi);
69  double sin2phi = sin(2*phi);
70 
71  double A = cos2phi;
72  double A_t = -2*sin2phi*phi_t;
73  double A_tt = -4*cos2phi*phi_t*phi_t-2*sin2phi*phi_tt;
74  double A_ttt = 8*sin2phi*pow(phi_t,3)-8*cos2phi*phi_t*phi_tt
75  -4*cos2phi*phi_t*phi_tt-2*sin2phi*phi_ttt;
76 
77  double B = sin2phi;
78  double B_t = 2*cos2phi*phi_t;
79  double B_tt = -4*sin2phi*phi_t*phi_t+2*cos2phi*phi_tt;
80  double B_ttt = -8*cos2phi*pow(phi_t,3) - 8*sin2phi*phi_t*phi_tt
81  -4*sin2phi*phi_t*phi_tt + 2*cos2phi*phi_ttt;
82 
83  double M[3][3] = {1+3*A,3*B,0, 3*B,1-3*A,0, 0,0,-2};
84  double M_t[3][3] = {3*A_t, 3*B_t, 0, 3*B_t, -3*A_t, 0, 0,0,0};
85  double M_tt[3][3] = {3*A_tt, 3*B_tt, 0, 3*B_tt, -3*A_tt, 0, 0,0,0};
86  double M_ttt[3][3] ={3*A_ttt, 3*B_ttt, 0, 3*B_ttt, -3*A_ttt, 0, 0,0,0};
87 
88  for(int i=0; i<3; ++i)for(int j=0; j<3; ++j){
89  I_tt[i][j] = (X_tt*M[i][j]+X*M_tt[i][j]+2*X_t*M_t[i][j])/6;
90  I_ttt[i][j] = (X_ttt*M[i][j]+X*M_ttt[i][j]+3*X_tt*M_t[i][j]+3*X_t*M_tt[i][j])/6;
91  }
92 }
93 
94 void quad_loss(double r, double r_t, double r_tt, double r_ttt, double phi,
95  double phi_t, double phi_tt, double phi_ttt, double& E_dot, double& Lz_dot)
96 
97 /* Compute rate of energy and angular momentum loss according to quadrupole formula
98  Specifically, for a two body system (in units of total mass, M:=m1+m2=1)
99  where object one is located at d1 = d*m2 and d2 =d*m1 where
100  d = (r*cos(phi),r*sin(phi)) this returns (dE/dt)/mu**2
101  and (dL/dt)/mu**2 where mu is the reduced mass
102  The arguments are r and its first three time derivatives
103  and phi and its first three time derivatives. */
104 
105 { double I_tt[3][3], I_ttt[3][3];
106  reduced_quad_dot(r,r_t,r_tt,r_ttt,phi,phi_t,phi_tt,phi_ttt, I_tt, I_ttt);
107 
108  double sum = 0;
109  for(int i=0; i<3; ++i)for(int j=0; j<3; ++j) sum +=I_ttt[i][j]*I_ttt[i][j];
110 
111  E_dot = -0.2*sum;
112 
113  // Assuming angular momentum only changes in z direction
114  sum = 0;
115  for(int i=0; i<3; ++i)sum += I_tt[0][i]*I_ttt[i][1]- I_tt[1][i]*I_ttt[i][0];
116  Lz_dot = -0.4*sum;
117 }
118 
119 
120 void f_util(double* y, double Jspin, double mu)
121 { r = y[0];
122  pr = y[1];
123  phi = y[2];
124  tau = y[3];
125  double& E = y[4];
126  double& L = y[5];
127  double a = Jspin +mu*L;
128 
129  r2 = r*r;
130  a2 = a*a;
131  r3 = r2*r;
132 
133  Delta = r2 + a2 - 2*r;
134  R02 = r2 + a2*(1+2/r);
135  Q=Delta/(E*R02-2*a*L/r); // Q=tau_dot
136 
137  w=(L*Q+2*a/r)/R02; // w=phi_dot
138  A=(w*w*(r3-a2)+2*a*w-1);
139  B=(a2-r)/r3;
140 
141  r_dot=Delta*Q*pr/r2;
142  pr_dot=A/r2/Q + B*pr*pr*Q;
143 
144  double r_dotdot, r_dotdotdot, wdot, wdotdot;
145  geo_higher_deriv(E, L, a, r_dotdot, r_dotdotdot, wdot, wdotdot);
146 
147  quad_loss(r, r_dot, r_dotdot, r_dotdotdot, phi, w, wdot, wdotdot, Edot, Ldot);
148  Edot = mu*Edot;
149  Ldot = mu*Ldot;
150 }
151 
152 
153 // Returns h plus and h cross (times r) of GW from quadrupole formula.
154 // See note above quad_loss
155 void h_quad(double r, double r_t, double r_tt, double r_ttt,
156  double phi, double phi_t, double phi_tt, double phi_ttt,
157  double& hplus, double& hcross)
158 {
159  double I_tt[3][3];
160  double I_ttt[3][3];
161  reduced_quad_dot(r, r_t, r_tt, r_ttt, phi, phi_t, phi_tt, phi_ttt, I_tt, I_ttt);
162 
163  hplus = 2*I_tt[0][0];
164  hcross = 2*I_tt[0][1];
165 }
166 
167 
168 // ud has Jspin, mu
169 int f(realtype t, N_Vector y, N_Vector ydot, void* ud)
170 { realtype *ydata, *ydotdata;
171  realtype* udr = (realtype*)ud;
172  ydata = NV_DATA_S(y);
173  ydotdata = NV_DATA_S(ydot);
174 
175  f_util(ydata, udr[0], udr[1]);
176  ydotdata[0] = r_dot;
177  ydotdata[1] = pr_dot;
178  ydotdata[2] = w;
179  ydotdata[3] = Q;
180  ydotdata[4] = Edot;
181  ydotdata[5] = Ldot;
182  return 0;
183 }
184 
185 geodesic::geodesic(double r0, double phi0, double E0, double L0, int dir, double Jspin,
186 double mu, double dt)
187 { if(dir!=1 && dir!=-1){
188  printf("Error... dir must be +-1\n");
189  exit(1);
190  }
191  y = N_VNew_Serial(6);
192  ydata = NV_DATA_S(y);
193  ydata[0] = r0;
194  ydata[1] = 0.0;
195  ydata[2] = phi0;
196  ydata[3] = 0.0;
197  ydata[4] = E0;
198  ydata[5] = L0;
199  udata[0] = Jspin;
200  udata[1] = mu;
201  tret = 0;
202  f_util(ydata, Jspin, mu);
203  double Q2 = Q*Q;
204  ydata[1] = dir*sqrt(fabs(r2/Delta/Q2*(1-2/::r-Q2-w*(R02*w-4*sqrt(a2)/::r))));
205 
206  cvode_mem =CVodeCreate(CV_ADAMS, CV_FUNCTIONAL);
207  if(!cvode_mem){
208  printf("cvode_mem initialization failed\n");
209  exit(1);
210  }
211  CVodeSetUserData(cvode_mem, udata);
212 
213  if(CVodeInit(cvode_mem, f, tret, y) != CV_SUCCESS){
214  printf("cvodeInit failed\n");
215  exit(1);
216  }
217 
218  if(CVodeSStolerances(cvode_mem, 1e-4, 1e-7)!= CV_SUCCESS){
219  printf("failed setting tolerances\n");
220  exit(1);
221  }
222 
223  r = pr = phi = tau = t = Et = Lt = hplus = hcross =0;
224 }
225 
227 { delete [] r;
228  delete [] pr;
229  delete [] phi;
230  delete [] tau;
231  delete [] t;
232  delete [] Et;
233  delete [] Lt;
234  delete [] hplus;
235  delete [] hcross;
236 }
237 
238 
239 double min(double x, double y)
240 { return x<y ? x : y;}
241 
242 bool geodesic::integrate(double D_t, int& N, double rmin, bool stop_alr)
243 { double dt = D_t/N;
244  this->r = new double[N+1];
245  this->pr = new double[N+1];
246  this->phi = new double[N+1];
247  this->tau = new double[N+1];
248  this->Et = new double[N+1];
249  this->Lt = new double[N+1];
250  this->t = new double[N+1];
251 
252  this->r[0] = ydata[0];
253  this->pr[0] = ydata[1];
254  this->phi[0] = ydata[2];
255  this->tau[0] = ydata[3];
256  this->Et[0] = ydata[4];
257  this->Lt[0] = ydata[5];
258  this->t[0] = tret;
259 
260  double r_stop = 0;
261  if(stop_alr) r_stop = 2*( 1+cos( 2*(acos(-min(udata[0] + udata[1]*this->Lt[0], 1))/3 )));
262  if(rmin>r_stop)r_stop = rmin;
263  int i=0;
264  while(i<N && r[i]>r_stop){
265  if(CVode(cvode_mem, tret+dt, y, &tret, CV_NORMAL)!=CV_SUCCESS)return false;
266  ++i;
267  this->r[i] = ydata[0];
268  this->pr[i] = ydata[1];
269  this->phi[i] = ydata[2];
270  this->tau[i] = ydata[3];
271  this->Et[i] = ydata[4];
272  this->Lt[i] = ydata[5];
273  this->t[i] = tret;
274  if(stop_alr){
275  r_stop = 2*( 1+cos( 2*(acos(-min(udata[0] + udata[1]*this->Lt[i], 1))/3 )));
276  if(rmin>r_stop)r_stop = rmin;
277  }
278  }
279  bool ret = (i==N);
280 
281  N=i+1;
282  hplus = new double[N];
283  hcross = new double[N];
284  double r_tt, r_ttt, phi_tt, phi_ttt;
285  double hp, hc;
286 
287  for(i = 0; i<N; ++i){
288  ydata[0] = this->r[i];
289  ydata[1] = this->pr[i];
290  ydata[2] = this->phi[i];
291  ydata[3] = this->tau[i];
292  ydata[4] = this->Et[i];
293  ydata[5] = this->Lt[i];
294  if(i==2000){
295  // ydata[0] = 7.256704e+00;
296  // ydata[1] = -4.276535e-02;
297  // ydata[2] = 5.112497e+01;
298  // ydata[3] = 1.728791e+03;
299  // ydata[4] = 9.438350e-01;
300  // ydata[5] = 3.180806e+00;
301  }
302  f_util(ydata, udata[0], udata[1]);
303  geo_higher_deriv(ydata[4], ydata[5], sqrt(a2), r_tt, r_ttt, phi_tt, phi_ttt);
304 
305  h_quad(::r,r_dot, r_tt, r_ttt, ::phi, w, phi_tt, phi_ttt, hp, hc);
306  hplus[i] = udata[1]*hp;
307  hcross[i] = udata[1]*hc;
308  }
309  return ret;
310 }
311 
312 
313 void printfutil(double* y)
314 { printf("%.6le %.6le %.6le %.6le %.6le %.6le\n", r, pr, phi, tau, r2, a2);
315  printf("%.6le %.6le %.6le %.6le %.6le %.6le\n", r3, Delta, R02, Q, A, B);
316  printf("%.6le %.6le %.6le %.6le %.6le\n",r_dot, w, pr_dot, Edot, Ldot);
317  double r_tt, r_ttt, phi_tt, phi_ttt;
318  double hp, hc;
319 
320  geo_higher_deriv(y[0], y[1], sqrt(a2), r_tt, r_ttt, phi_tt, phi_ttt);
321  printf("%.6le %.6le %.6le %.6le %.6le\n", sqrt(a2), r_tt, r_ttt, phi_tt, phi_ttt);
322  h_quad(::r,r_dot, r_tt, r_ttt, ::phi, w, phi_tt, phi_ttt, hp, hc);
323  printf("%.6le %.6le\n", hp, hc);
324 }
wavearray< double > t(hp.size())
double * Et
Definition: geodesics.hh:18
static const double C
Definition: GNGen.cc:10
static double r3
Definition: geodesics.cc:8
static double B
Definition: geodesics.cc:8
static double r
Definition: geodesics.cc:8
detector D
Definition: TestBandPass.C:15
void geo_higher_deriv(double E, double L, double a, double &r_dotdot, double &r_dotdotdot, double &wdot, double &wdotdot)
Definition: geodesics.cc:15
double min(double x, double y)
Definition: geodesics.cc:239
static double R02
Definition: geodesics.cc:8
printf("total live time: non-zero lags = %10.1f \n", liveTot)
static double Q
Definition: geodesics.cc:8
wavearray< double > a(hp.size())
cout<< endl;cout<< "ts size = "<< ts.size()<< " ts rate = "<< ts.rate()<< endl;tf.Forward(ts, wdm);int levels=tf.getLevel();cout<< "tf size = "<< tf.size()<< endl;double dF=tf.resolution();double dT=1./(2 *dF);cout<< "rate(hz) : "<< RATE<< "\t layers : "<< nLAYERS<< "\t dF(hz) : "<< dF<< "\t dT(ms) : "<< dT *1000.<< endl;int itime=TIME_PIXEL_INDEX;int ifreq=FREQ_PIXEL_INDEX;int index=(levels+1)*itime+ifreq;double time=itime *dT;double freq=(ifreq >0)?ifreq *dF:dF/4;cout<< endl;cout<< "PIXEL TIME = "<< time<< " sec "<< endl;cout<< "PIXEL FREQ = "<< freq<< " Hz "<< endl;cout<< endl;wavearray< double > x
static double w
Definition: geodesics.cc:8
static double Ldot
Definition: geodesics.cc:8
geodesic(double r0, double phi0, double E0, double L0, int dir, double Jspin, double mu=0, double dt=1)
Definition: geodesics.cc:185
void * cvode_mem
Definition: geodesics.hh:24
wavearray< double > hp
Definition: DrawInspiral.C:43
#define M
Definition: UniqSLagsList.C:3
double * hcross
Definition: geodesics.hh:18
int j
Definition: cwb_net.C:10
i drho i
bool integrate(double D_t, int &N, double rmin=0, bool stop_alr=false)
Definition: geodesics.cc:242
#define N
void reduced_quad_dot(double r, double r_t, double r_tt, double r_ttt, double phi, double phi_t, double phi_tt, double phi_ttt, double(&I_tt)[3][3], double(&I_ttt)[3][3])
Definition: geodesics.cc:61
double * t
Definition: geodesics.hh:18
double G
Definition: DrawEBHH.C:12
static double r2
Definition: geodesics.cc:8
static double Edot
Definition: geodesics.cc:8
double * hplus
Definition: geodesics.hh:18
static double pr_dot
Definition: geodesics.cc:8
void printfutil(double *y)
Definition: geodesics.cc:313
static double tau
Definition: geodesics.cc:8
realtype tret
Definition: geodesics.hh:22
static double A
Definition: geodesics.cc:8
double F
double * r
Definition: geodesics.hh:18
double e
double dt
double * phi
Definition: geodesics.hh:18
static double r_dot
Definition: geodesics.cc:8
double * Lt
Definition: geodesics.hh:18
static double phi
Definition: geodesics.cc:8
double fabs(const Complex &x)
Definition: numpy.cc:37
static double a2
Definition: geodesics.cc:8
N_Vector y
Definition: geodesics.hh:21
realtype udata[2]
Definition: geodesics.hh:22
void h_quad(double r, double r_t, double r_tt, double r_ttt, double phi, double phi_t, double phi_tt, double phi_ttt, double &hplus, double &hcross)
Definition: geodesics.cc:155
void f_util(double *y, double Jspin, double mu)
Definition: geodesics.cc:120
double * tau
Definition: geodesics.hh:18
int f(realtype t, N_Vector y, N_Vector ydot, void *ud)
Definition: geodesics.cc:169
static double pr
Definition: geodesics.cc:8
wavearray< double > y
Definition: Test10.C:31
static double Delta
Definition: geodesics.cc:8
exit(0)
realtype * ydata
Definition: geodesics.hh:23
double * pr
Definition: geodesics.hh:18
void quad_loss(double r, double r_t, double r_tt, double r_ttt, double phi, double phi_t, double phi_tt, double phi_ttt, double &E_dot, double &Lz_dot)
Definition: geodesics.cc:94