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
| import numpy as np import scipy.constants as cons import scipy.integrate as integrate import multiprocessing as mp import time
sun = 1.98855e30 mpc = 1e6 * cons.parsec
length = np.sqrt(3) * 1e8
def chirp(mass1, mass2): return np.power(mass1*mass2, 3/5) / np.power(mass1+mass2, 1/5)
def frequency(tc, mass1, mass2): return np.power(5,3/8)/(8*cons.pi)*np.power(np.power(cons.c,3)/(cons.G*chirp(mass1, mass2)),5/8)*np.power((-tc),-3/8)
def min_f(mass1, mass2, tc): return frequency(-tc, mass1, mass2)
def hf(f, mass1, mass2, tc, dis): phif = 2*np.pi*f*tc-cons.pi/4+3/4*np.power(8*cons.pi*cons.G*chirp(mass1, mass2)*f/np.power(cons.c,3),-5/3) return np.sqrt(5/384)*np.power(cons.G,5/6)*np.power(cons.c,-3/2)*np.power(chirp(mass1, mass2),5/6)*np.power(np.pi,-2/3)*np.power(f,-7/6)*np.exp(1j*phif)/dis
def sensitive(f): return (4*1e-30*(1+1e-4/f)/np.power((2*np.pi*f), 4)+1e-24)*(1+0.6*np.power((f/0.28),2))/np.power(length, 2)
def norm(f, mass1, mass2): freq = np.sqrt(5/384)*np.power(cons.G,5/6)*np.power(cons.c,-3/2)*np.power(chirp(mass1, mass2),5/6)*np.power(np.pi,-2/3)*np.power(f,-7/6) return np.power(freq, 2) / sensitive(f)
def partial(h1, h2, f, mass1, mass2, tc, dis): if h1 == 'm1' and h2 == 'm1': return (hf(f, mass1+step1, mass2, tc, dis) + hf(f, mass1-step1, mass2, tc, dis) - 2*hf(f, mass1, mass2, tc, dis))/np.power(step1, 2), step1, step1 elif h1 == 'm2' and h2 == 'm2': return (hf(f, mass1, mass2+step1, tc, dis) + hf(f, mass1, mass2-step1, tc, dis) - 2*hf(f, mass1, mass2, tc, dis))/np.power(step1, 2), step1, step1 elif h1 == 'tc' and h2 == 'tc': return (hf(f, mass1, mass2, tc+step2, dis) + hf(f, mass1, mass2, tc-step2, dis) - 2*hf(f, mass1, mass2, tc, dis))/np.power(step2, 2), step2, step2 elif (h1 == 'm1' and h2 == 'm2') or (h1 == 'm2' and h2 == 'm1'): return (hf(f, mass1+step1, mass2+step1, tc, dis) + hf(f, mass1-step1, mass2-step1, tc, dis) - hf(f, mass1+step1, mass2-step1, tc, dis) - hf(f, mass1-step1, mass2+step1, tc, dis))/np.power(2*step1, 2), step1, step1 elif (h1 == 'm1' and h2 == 'tc') or (h1 == 'tc' and h2 == 'm1'): return (hf(f, mass1+step1, mass2, tc+step2, dis) + hf(f, mass1-step1, mass2, tc-step2, dis) - hf(f, mass1+step1, mass2, tc-step2, dis) - hf(f, mass1-step1, mass2, tc+step2, dis))/(2*step1*2*step2), step1, step2 elif (h1 == 'm2' and h2 == 'tc') or (h1 == 'tc' and h2 == 'm2'): return (hf(f, mass1, mass2+step1, tc+step2, dis) + hf(f, mass1, mass2-step1, tc-step2, dis) - hf(f, mass1, mass2+step1, tc-step2, dis) - hf(f, mass1, mass2-step1, tc+step2, dis))/(2*step1*2*step2), step1, step2
def inner(f, h1, h2, mass1, mass2, tc, dis): par = partial(h1, h2, f, mass1, mass2, tc, dis) return (hf(f, mass1, mass2, tc, dis).conjugate()*par[0]/sensitive(f)).real
def inter(h1, h2, mass1, mass2, tc): fisco = np.power(cons.c, 3) / (np.power(6, 2/3)*cons.pi*cons.G*(mass1+mass2)) v, _ = integrate.quad(norm, min_f(mass1, mass2, tc), fisco, args=(mass1, mass2)) dis = np.sqrt(4 * v) v, _ = integrate.quad(inner, min_f(mass1, mass2, tc), fisco, args=(h1, h2, mass1, mass2, tc, dis), limit=100) return -2 * v
def martrix(args): mass1 = args[0] mass2 = args[1] tc = args[2] gij = [inter(h1, h2, mass1, mass2, tc) for h1 in ['m1', 'm2', 'tc'] for h2 in ['m1', 'm2', 'tc']] gij = np.reshape(gij, (3, 3)) return np.sqrt(np.abs(np.linalg.det(gij)))
step1 = 1e-7*95*sun step2 = 1e-7*5*cons.year
if __name__ == '__main__': num = 400 time1 = time.time() mass1 = np.random.uniform(5, 100, num)*sun mass2 = np.random.uniform(5, 100, num)*sun tc = np.random.uniform(0, 5, num)*cons.year with mp.Pool() as p: a = p.map(martrix, [(m1, m2, tc) for m1, m2, tc in zip(mass1, mass2, tc)]) ans = sum(a) * np.power(95*sun, 2) * 5*cons.year / num / np.power(0.03, 3/2) print(ans) with open('result.txt', 'a') as f: f.write(f'{step1:5e}:{ans:.5e}\n') print(time.time() - time1)
|