Logo coherent WaveBurst  
Library Reference Guide
Logo
eBBH.cc
Go to the documentation of this file.
1 /*
2 # Copyright (C) 2019 Sergey Klimenko, Valentin Necula
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 3 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 this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17 
18 
19 #include "eBBH.hh"
20 
21 #include "egw_model.hh"
22 #include "geodesics.hh"
23 #include "merger.hh"
24 #include "numpy.hh"
25 
26 
27 #include "stdio.h"
28 #include "stdlib.h"
29 #include "math.h"
30 
31 inline double min(double x, double y)
32 { return x<y? x: y;}
33 
34 int Sample(Complex* H, double* t, int N, double totalMass, double Rate, wavearray<double>& hps, wavearray<double>& hxs)
35 { const double C = 299792458;
36  const double G = 6.67428e-11;
37  const double SolarMass = 1.98892e30;
38  const double L = G/C/C*SolarMass*totalMass;
39  const double T = L/C; //printf("T = %lf\n", T);
40 
41  double* tt = new double[N];
42 
43  for(int i=0; i<N; ++i){
44  tt[i] = t[i]*T;
45  if(i)tt[i] -= tt[0];
46  }
47  tt[0] = 0;
48  //printf("T*16384 = %lf\n", T*16384);
49  double tMax = tt[N-1]; //printf("tMax = %lf\n", tMax);
50  int nSamples = 0;
51  if(tMax*Rate<2.1e9)nSamples = tMax*Rate;
52  //printf("nSamples = %d\n", nSamples);
53 
54  hps.resize(nSamples); hps.rate(Rate);
55  hxs.resize(nSamples); hxs.rate(Rate);
56 
57  int j=1;
58  for(int i=0; i<nSamples; ++i){
59  double ts = i/Rate;
60  while(ts>tt[j])++j;
61  if(j>=N)printf("ERROR\n");
62  double frac = (ts - tt[j-1])/(tt[j] - tt[j-1]);
63  hps[i] = H[j-1].Re() + (H[j].Re() - H[j-1].Re())*frac;
64  hxs[i] = H[j-1].Im() + (H[j].Im() - H[j-1].Im())*frac;
65  }
66  delete [] tt;
67 
68  return nSamples;
69 }
70 
71 int getEBBH(double m1, double m2, double rmin0, double e0, wavearray<double>& Hp, wavearray<double>& Hx, double t_end)
72 { if(m1<0 || m2<0){
73  printf("Error! masses must be >=0\n");
74  return -1;
75  }
76 
77  if(rmin0<0){
78  printf("Error! rmin must be >=0\n");
79  return -2;
80  }
81  if(e0>1){
82  printf("Error! Orbit must be initially parabolic or bound.\n");
83  return -3;
84  }
85 
86  //double q = m1*m2/(m1+m2)/(m1+m2);
87  double q = m1/m2;
88  if(q>1)q=1./q;
89  double rmin = rmin0;
90  double e = e0;
91  double Mbh = 1/(1+q);
92  double Mns = 1 - Mbh;
93  //printf("Mbh = %.3lf\nMns = %.3lf\n", Mbh, Mns);
94  double mu = Mns*Mbh;
95 
96  double abh = 0.0;
97  double dt = 1;
98  double a_final = 0;
99  double t_post_merger = 400;
100 
101  double Jspin = abh*Mbh*Mbh;
102  double L0 = ang_mom_eff_geo(rmin0, e0, Jspin, mu);
103  double a0 = Jspin+mu*L0;
104  double E0 = energy_geo(rmin0, e0, a0);
105  double r0 = 1000;
106  if (e0<1 && r0 > rmin0*(1+e0)/(1-e0)) r0 = rmin0*(1+e0)/(1-e0);
107 
108  int dir = -1; //inward
109  int N_plot = t_end/dt; //printf("%d\n", N_plot);
110  double phi0 = 0;
111  //printf("%.6le %.6le %.6le %.6le %d %.6le %.6le\n", r0, phi0, E0, L0, dir, Jspin, mu);
112  geodesic geo(r0, phi0, E0, L0, dir, Jspin, mu);
113 
114  bool success = geo.integrate(t_end, N_plot, 0, true); // memory LEAK!
115 
116  double tmerge;
117  if (success){
118  tmerge = -1;
119  t_post_merger=0;
120  }
121  else{
122  double* r_LR = new double[N_plot];
123  for(int i=0; i<N_plot; ++i)
124  r_LR[i] = 2*(1+cos(2*(acos(-min(mu*geo.Lt[i] + Jspin, 1.))/3))) - geo.r[i]; //Light ring
125  tmerge = interp(0, r_LR, geo.t, N_plot, 1., 1.);
126  delete [] r_LR;
127  }
128 
129  int Ntsig = (geo.t[N_plot-1]+t_post_merger)/dt;
130  double* tsig = new double[Ntsig];
131  for(int i=0; i<Ntsig; ++i) tsig[i] = dt*i;
132 
133  double* hr = interp(tsig, Ntsig, geo.t, geo.hplus, N_plot, 0, 0);
134  double* hi = interp(tsig, Ntsig, geo.t, geo.hcross, N_plot, 0, 0);
135 
136  Complex* hsig = new Complex[Ntsig];
137  for(int i=0; i<Ntsig; ++i)hsig[i] = Complex(hr[i], hi[i]);
138 
139  a_final = mu*geo.Lt[N_plot-1] + abh*Mbh*Mbh; // Spin of final BH
140 
141  double tstart_merger = tmerge;
142  if (tmerge>0) irs_merger(dt, tmerge, tsig, hsig, Ntsig, a_final, tstart_merger);
143 
144  int retVal = Sample(hsig, tsig, Ntsig, m1+m2, 16384., Hp, Hx)==0;
145  delete [] hsig;
146  delete [] hr;
147  delete [] hi;
148  delete [] tsig;
149  return retVal;
150 }
wavearray< double > t(hp.size())
static const double C
Definition: GNGen.cc:28
double min(double x, double y)
Definition: eBBH.cc:31
virtual void rate(double r)
Definition: wavearray.hh:141
double m1
double Im() const
Definition: numpy.hh:33
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<< "\ layers : "<< nLAYERS<< "\ dF(hz) : "<< dF<< "\ 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
double SolarMass()
Definition: constants.hh:202
double * hcross
Definition: geodesics.hh:36
int j
Definition: cwb_net.C:28
i drho i
bool integrate(double D_t, int &N, double rmin=0, bool stop_alr=false)
Definition: geodesics.cc:270
#define N
double * t
Definition: geodesics.hh:36
int Sample(Complex *H, double *t, int N, double totalMass, double Rate, wavearray< double > &hps, wavearray< double > &hxs)
Definition: eBBH.cc:34
double G
Definition: DrawEBHH.C:12
double * hplus
Definition: geodesics.hh:36
printf("total live time: non-zero lags = %10.1f \, liveTot)
double * r
Definition: geodesics.hh:36
double e
double dt
double * Lt
Definition: geodesics.hh:36
double e0
Definition: RescaleEBBH.C:17
double T
Definition: testWDM_4.C:11
wavearray< double > ts(N)
double interp(double v, double *x, double *y, int n)
Definition: numpy.cc:21
int getEBBH(double m1, double m2, double rmin0, double e0, wavearray< double > &Hp, wavearray< double > &Hx, double t_end)
Definition: eBBH.cc:71
double m2
double energy_geo(double rp, double e, double a)
Definition: egw_model.cc:227
double ang_mom_eff_geo(double rp, double e, double Jspin, double mu)
Definition: egw_model.cc:260
virtual void resize(unsigned int)
Definition: wavearray.cc:463
wavearray< double > y
Definition: Test10.C:31
void irs_merger(double dt, double tmerge, double *tsig, Complex *hsig, int lentsig, double a, double tstart=-1)
Definition: merger.cc:32
double Re() const
Definition: numpy.hh:32
Definition: numpy.hh:29