forked from mikekatz04/LATW
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pnbeyondGR_example.py
235 lines (200 loc) · 7.13 KB
/
pnbeyondGR_example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# we need to import an integrator and elliptic integrals
import numpy as np
from mpmath import *
import mpmath as mp
from scipy.integrate import DOP853
# base classes
from few.utils.baseclasses import TrajectoryBase
from few.utils.baseclasses import SchwarzschildEccentric
# settings for elliptic integrals
mp.dps = 25
mp.pretty = True
# constants from our package
from few.utils.constants import MTSUN_SI, YRSID_SI, Pi
# for common interface with C/mathematica
def Power(x, n):
return x**n
def Sqrt(x):
return np.sqrt(x)
# this is class object just to hold epsilon as it steps
# this class is instantiated and then run like the derivative function in the integrator (ex. dydt)
class PN:
def __init__(self, epsilon, modification):
self.epsilon = epsilon
self.modification = modification
def __call__(self, t, y):
# mass ratio
epsilon = self.epsilon
# extract the four evolving parameters
p, e, Phi_phi, Phi_r = y
# guard against bad integration steps
if e >= 1.0 or e < 1e-2 or p < 6.0 or (p - 6 - 2 * e) < 0.1:
return [0.0, 0.0, 0.0, 0.0]
# perform elliptic calculations
EllipE = ellipe(4 * e / (p - 6.0 + 2 * e))
EllipK = ellipk(4 * e / (p - 6.0 + 2 * e))
EllipPi1 = ellippi(
16 * e / (12.0 + 8 * e - 4 * e * e - 8 * p + p * p),
4 * e / (p - 6.0 + 2 * e),
)
EllipPi2 = ellippi(
2 * e * (p - 4) / ((1.0 + e) * (p - 6.0 + 2 * e)), 4 * e / (p - 6.0 + 2 * e)
)
# Azimuthal frequency
Omega_phi = (2 * Power(p, 1.5)) / (
Sqrt(-4 * Power(e, 2) + Power(-2 + p, 2))
* (
8
+ (
(
-2
* EllipPi2
* (6 + 2 * e - p)
* (3 + Power(e, 2) - p)
* Power(p, 2)
)
/ ((-1 + e) * Power(1 + e, 2))
- (EllipE * (-4 + p) * Power(p, 2) * (-6 + 2 * e + p))
/ (-1 + Power(e, 2))
+ (
EllipK
* Power(p, 2)
* (28 + 4 * Power(e, 2) - 12 * p + Power(p, 2))
)
/ (-1 + Power(e, 2))
+ (
4
* (-4 + p)
* p
* (2 * (1 + e) * EllipK + EllipPi2 * (-6 - 2 * e + p))
)
/ (1 + e)
+ 2
* Power(-4 + p, 2)
* (
EllipK * (-4 + p)
+ (EllipPi1 * p * (-6 - 2 * e + p)) / (2 + 2 * e - p)
)
)
/ (EllipK * Power(-4 + p, 2))
)
)
# Post-Newtonian calculations
yPN = pow(Omega_phi, 2.0 / 3.0)
EdotPN = (
(96 + 292 * Power(e, 2) + 37 * Power(e, 4))
/ (15.0 * Power(1 - Power(e, 2), 3.5))
* pow(yPN, 5)
)
LdotPN = (
(4 * (8 + 7 * Power(e, 2)))
/ (5.0 * Power(-1 + Power(e, 2), 2))
* pow(yPN, 7.0 / 2.0)
)
# flux
Edot = -epsilon * (EdotPN)
Ldot = -epsilon * (LdotPN)
# time derivatives
pdot = (
-2
* (
Edot
* Sqrt((4 * Power(e, 2) - Power(-2 + p, 2)) / (3 + Power(e, 2) - p))
* (3 + Power(e, 2) - p)
* Power(p, 1.5)
+ Ldot * Power(-4 + p, 2) * Sqrt(-3 - Power(e, 2) + p)
)
) / (4 * Power(e, 2) - Power(-6 + p, 2))
edot = -(
(
Edot
* Sqrt((4 * Power(e, 2) - Power(-2 + p, 2)) / (3 + Power(e, 2) - p))
* Power(p, 1.5)
* (
18
+ 2 * Power(e, 4)
- 3 * Power(e, 2) * (-4 + p)
- 9 * p
+ Power(p, 2)
)
+ (-1 + Power(e, 2))
* Ldot
* Sqrt(-3 - Power(e, 2) + p)
* (12 + 4 * Power(e, 2) - 8 * p + Power(p, 2))
)
/ (e * (4 * Power(e, 2) - Power(-6 + p, 2)) * p)
)
Phi_phi_dot = Omega_phi
Phi_r_dot = (
p * Sqrt((-6 + 2 * e + p) / (-4 * Power(e, 2) + Power(-2 + p, 2))) * Pi
) / (
8 * EllipK
+ (
(-2 * EllipPi2 * (6 + 2 * e - p) * (3 + Power(e, 2) - p) * Power(p, 2))
/ ((-1 + e) * Power(1 + e, 2))
- (EllipE * (-4 + p) * Power(p, 2) * (-6 + 2 * e + p))
/ (-1 + Power(e, 2))
+ (EllipK * Power(p, 2) * (28 + 4 * Power(e, 2) - 12 * p + Power(p, 2)))
/ (-1 + Power(e, 2))
+ (
4
* (-4 + p)
* p
* (2 * (1 + e) * EllipK + EllipPi2 * (-6 - 2 * e + p))
)
/ (1 + e)
+ 2
* Power(-4 + p, 2)
* (
EllipK * (-4 + p)
+ (EllipPi1 * p * (-6 - 2 * e + p)) / (2 + 2 * e - p)
)
)
/ Power(-4 + p, 2)
)
pdot *= 1 + self.modification
edot *= 1 + self.modification
dydt = [pdot, edot, Phi_phi_dot, Phi_r_dot]
return dydt
# this is the actual class that implements a PN trajectory. It uses the PN class in the integrator.
class ModifiedPnTrajectory(TrajectoryBase):
# for common interface with *args and **kwargs
def __init__(self, *args, **kwargs):
pass
# required by the trajectory base class
def get_inspiral(self, M, mu, a, p0, e0, x0, modification, T=1.0, **kwargs):
# set up quantities and integrator
y0 = [p0, e0, 0.0, 0.0]
T = T * YRSID_SI / (M * MTSUN_SI)
Msec = M * MTSUN_SI
epsilon = mu / M
integrator = DOP853(PN(epsilon, modification), 0.0, y0, T)
t_out, p_out, e_out = [], [], []
Phi_phi_out, Phi_r_out = [], []
t_out.append(0.0)
p_out.append(p0)
e_out.append(e0)
Phi_phi_out.append(0.0)
Phi_r_out.append(0.0)
# run the integrator down to T or separatrix
run = True
while integrator.t < T and run:
integrator.step()
p, e, Phi_phi, Phi_r = integrator.y
t_out.append(integrator.t * Msec)
p_out.append(p)
e_out.append(e)
Phi_phi_out.append(Phi_phi)
Phi_r_out.append(Phi_r)
if (p - 6 - 2 * e) < 0.1:
run = False
# read out data. It must return length 6 tuple
t = np.asarray(t_out)
p = np.asarray(p_out)
e = np.asarray(e_out)
Phi_phi = np.asarray(Phi_phi_out)
Phi_r = np.asarray(Phi_r_out)
# need to add polar info
Phi_theta = Phi_phi.copy() # by construction
x = np.ones_like(Phi_theta)
return (t, p, e, x, Phi_phi, Phi_theta, Phi_r)