Esempio n. 1
0
def get_k(row):
    sim = rebound.SimulationArchive(sim_names + "_sa_%d.bin" % (row[0]))[0]
    #     print(sim)
    p2 = sim.particles[2]
    row['h'] = p2.e * np.sin(p2.pomega)
    row['k'] = p2.e * np.cos(p2.pomega)
    avars = Andoyer.from_Simulation(sim,
                                    a10=sim.particles[1].a,
                                    j=5,
                                    k=1,
                                    i1=1,
                                    i2=2,
                                    average=False)
    row['Z12'] = avars.Z
    row['Zcom12'] = avars.Zcom
    avars = Andoyer.from_Simulation(sim,
                                    a10=sim.particles[1].a,
                                    j=4,
                                    k=1,
                                    i1=2,
                                    i2=3,
                                    average=False)
    row['Z23'] = avars.Z
    row['Zcom23'] = avars.Zcom
    row['e1'] = sim.particles[1].e
    row['e2'] = sim.particles[2].e
    row['e3'] = sim.particles[3].e
    row['m1'] = sim.particles[1].m
    row['m2'] = sim.particles[2].m
    row['m3'] = sim.particles[3].m
    return row
Esempio n. 2
0
    def test_rotational_invariance(self):
        j=4
        k=1
        avars = Andoyer.from_Simulation(self.sim, j, k, i1=1, i2=2)

        rot = np.pi/3.
        ps = self.sim.particles
        simrot = rebound.Simulation()
        simrot.G = self.sim.G
        simrot.add(m=ps[0].m)
        for p in ps[1:]:
            simrot.add(m=p.m, a=p.a, e=p.e, inc=p.inc, Omega=p.Omega+rot, pomega=p.pomega+rot, l=p.l+rot)
        simrot.move_to_com()

        avarsrot = Andoyer.from_Simulation(simrot, j, k, i1=1, i2=2)
        self.assertAlmostEqual(avars.X, avarsrot.X, delta=self.delta) 
        self.assertAlmostEqual(avars.Y, avarsrot.Y, delta=self.delta) 
        self.assertAlmostEqual(avars.Zcom, avarsrot.Zcom, delta=self.delta) 
        self.assertAlmostEqual(np.cos(avars.phiZcom+rot), np.cos(avarsrot.phiZcom), delta=self.delta) 
        self.assertAlmostEqual(avars.B, avarsrot.B, delta=self.delta) 
        self.assertAlmostEqual(avars.dKprime, avarsrot.dKprime, delta=self.delta) 
        self.assertAlmostEqual(np.cos(avars.theta+k*rot), np.cos(avarsrot.theta), delta=self.delta) 
        p = avars.params
        fac = (p['m1']*p['sLambda10'] + p['m2']*p['sLambda20'])/p['K0']
        self.assertAlmostEqual(np.cos(avars.theta1+fac*rot), np.cos(avarsrot.theta1), delta=self.delta) 
Esempio n. 3
0
    def test_ecom(self):
        j = 57
        k = 2
        sim = rebound.Simulation()
        sim.G = 4 * np.pi**2
        sim.add(m=1.)
        sim.add(m=1.e-6,
                e=0.01,
                P=1.,
                pomega=-np.pi / 6,
                f=np.pi,
                jacobi_masses=True)
        sim.add(m=3.e-6,
                e=0.03,
                pomega=np.pi / 3,
                P=float(j) / (j - k),
                jacobi_masses=True)  #float(j)/(j-k), theta=3.14)
        sim.move_to_com()
        ps = sim.particles
        e1x = ps[1].e * np.cos(ps[1].pomega)
        e1y = ps[1].e * np.sin(ps[1].pomega)
        e2x = ps[2].e * np.cos(ps[2].pomega)
        e2y = ps[2].e * np.sin(ps[2].pomega)

        avars = Andoyer.from_Simulation(sim, j, k, a10=1.02, average=True)
        m1 = avars.params['m1']
        m2 = avars.params['m2']
        ecomx = (m1 * e1x + m2 * e2x) / (m1 + m2)
        ecomy = (m1 * e1y + m2 * e2y) / (m1 + m2)
        ecomsim = np.sqrt(ecomx**2 + ecomy**2)

        self.assertAlmostEqual(avars.Zcom, ecomsim, delta=1.e-3)
        phiecomsim = np.arctan2(ecomy, ecomx)
        self.assertAlmostEqual(avars.phiZcom, phiecomsim, delta=1.e-3)
Esempio n. 4
0
    def test_ZsGammaConversion(self):
        avars = Andoyer.from_Simulation(self.sim, 4, 1)
        Z = avars.Z
        phiZ = avars.psi1
        Zcom = avars.Zcom
        phiZcom = avars.phiZcom
        sGamma1, gamma1, sGamma2, gamma2 = avars.Zs_to_sGammas(Z, phiZ, Zcom, phiZcom)
        nZ, nphiZ, nZcom, nphiZcom = avars.sGammas_to_Zs(sGamma1, gamma1, sGamma2, gamma2)
        self.assertAlmostEqual(nZ,Z, delta=1.e-15)
        self.assertAlmostEqual(np.mod(nphiZ, 2*np.pi), np.mod(phiZ, 2*np.pi), delta=1.e-15)
        self.assertAlmostEqual(nZcom, Zcom, delta=1.e-15)
        self.assertAlmostEqual(np.mod(nphiZcom, 2*np.pi), np.mod(phiZcom, 2*np.pi), delta=1.e-15)

        # should also be equivalent for 2 massive particles to rotation
        pvars = Poincare.from_Simulation(self.sim)
        ps = pvars.particles
        p = avars.params
        f, g = p['f'], p['g']
        ff = f*np.sqrt(p['eta']/p['m1']/p['sLambda10'])
        gg = g*np.sqrt(p['eta']/p['m2']/p['sLambda20'])
        norm = np.sqrt(ff*ff + gg*gg)
        psirotmatrix = np.array([[ff,gg],[-gg,ff]]) / norm
        invpsirotmatrix = np.array([[ff,-gg],[gg,ff]]) / norm
        Psi1,psi1,Psi2,psi2 = self.rotate_actions(ps[1].Gamma/p['eta'],ps[1].gamma,ps[2].Gamma/p['eta'],ps[2].gamma, psirotmatrix)
        self.assertAlmostEqual(Psi1, avars.Psi1, delta=1.e-15)
        self.assertAlmostEqual(np.mod(psi1, 2*np.pi), np.mod(avars.psi1, 2*np.pi), delta=1.e-15)
        self.assertAlmostEqual(Psi2, avars.Psi2, delta=1.e-15)
        self.assertAlmostEqual(np.mod(psi2, 2*np.pi), np.mod(avars.psi2, 2*np.pi), delta=1.e-15)
Esempio n. 5
0
 def test_dP(self):
     j=5
     k=2
     sim = rebound.Simulation()
     sim.add(m=1.)
     sim.add(m=1.e-6, P=1.)
     sim.add(m=3.e-6, P=1.68)
     sim.move_to_com()
     avars = Andoyer.from_Simulation(sim,j,k, a10=0.32, average=False) # real a0 ~0.29, 10% err
     self.assertAlmostEqual(1.68-float(j)/(j-k), avars.dP, delta=0.01) # err is da^2 or smaller, so 1%
Esempio n. 6
0
 def test_masses(self):
     # turn off averaging for all transformation tests since averaging
     # is not symmetric back and forth (there's diff of O(s^2))
     masses = [1., 1.e-5, 1.e-7, 1.e-3]
     pairs = [[1,2], [2,3], [1,3]]
     for i1, i2 in pairs:
         m = [masses[0], masses[i1], masses[i2]]
         avars = Andoyer.from_Simulation(self.sim, 4, 1, average=False, i1=i1, i2=i2)
         sim = avars.to_Simulation(masses=m, average=False)
         self.compare_particles(self.sim, sim, i1, 1, self.delta)
         self.compare_particles(self.sim, sim, i2, 2, self.delta)
Esempio n. 7
0
    def test_scale_invariance(self):
        avars = Andoyer.from_Simulation(self.sim, 4, 1, i1=1, i2=2)
        
        mfac = 3.
        dfac = 0.05
        vfac = np.sqrt(mfac/dfac)
        for p in self.sim.particles:
            p.m *= mfac 
            p.vx *= vfac
            p.vy *= vfac
            p.vz *= vfac
            p.x *= dfac
            p.y *= dfac
            p.z *= dfac

        avarsscaled = Andoyer.from_Simulation(self.sim, 4, 1, i1=1, i2=2)
        self.assertAlmostEqual(avars.X, avarsscaled.X, delta=self.delta) 
        self.assertAlmostEqual(avars.Y, avarsscaled.Y, delta=self.delta) 
        self.assertAlmostEqual(avars.Zcom, avarsscaled.Zcom, delta=self.delta) 
        self.assertAlmostEqual(np.cos(avars.phiZcom), np.cos(avarsscaled.phiZcom), delta=self.delta) 
        self.assertAlmostEqual(avars.B, avarsscaled.B, delta=self.delta) 
        self.assertAlmostEqual(avars.dKprime, avarsscaled.dKprime, delta=self.delta) 
        self.assertAlmostEqual(np.cos(avars.theta), np.cos(avarsscaled.theta), delta=self.delta) 
        self.assertAlmostEqual(np.cos(avars.theta1), np.cos(avarsscaled.theta1), delta=self.delta) 
Esempio n. 8
0
    def test_H(self):
        j=3
        k=1
        a10 = 1.02
        sim = rebound.Simulation()
        sim.G = 4*np.pi**2
        sim.add(m=1.)
        sim.add(m=1.e-6, e=0.01, P=1., pomega=-np.pi/2, f=np.pi, jacobi_masses=True)
        sim.add(m=3.e-6, e=0.03, pomega=np.pi/2, P=float(j)/(j-k), jacobi_masses=True)#float(j)/(j-k), theta=3.14)
        sim.move_to_com()
        avars = Andoyer.from_Simulation(sim,j,k, a10=a10, average=True) 
        p = avars.params
        pvars = Poincare.from_Simulation(sim, average=True) 
        sGamma1 = pvars.particles[1].sGamma
        sGamma2 = pvars.particles[2].sGamma
        sLambda1 = pvars.particles[1].sLambda
        sLambda2 = pvars.particles[2].sLambda
        lambda1 = pvars.particles[1].l
        lambda2 = pvars.particles[2].l
        gamma1 = pvars.particles[1].gamma
        gamma2 = pvars.particles[2].gamma
        n10 = np.sqrt(p['G']*p['M1']/p['a10']**3)
        n20 = np.sqrt(p['G']*p['M2']/p['a10']**3*p['alpha']**3)
        z1 = np.sqrt(2*sGamma1/p['sLambda10'])
        z2 = np.sqrt(2*sGamma2/p['sLambda20'])
        Hkep = -0.5*(n10*p['m1']*p['sLambda10']**3/sLambda1**2 + n20*p['m2']*p['sLambda20']**3/sLambda2**2)
        sL10 = p['sLambda10']
        sL20 = p['sLambda20']
        Hkepexpanded = -n10*p['m1']*sL10/2*(1. - 2*avars.dL1hat + 3*avars.dL1hat**2)-n20*p['m2']*sL20/2*(1. - 2*avars.dL2hat + 3*avars.dL2hat**2)
        Hresprefac = -p['G']*p['m1']*p['m2']/p['a10']*p['alpha']
        Hres = Hresprefac*(p['f']*z1*np.cos(j*lambda2 - (j-k)*lambda1 + gamma1)+p['g']*z2*np.cos(j*lambda2 - (j-k)*lambda1 + gamma2))
        H0 = -p['n0']*p['K0']/2
        H1 = p['eta']*p['n0']*avars.dK*(1-1.5*p['eta']/p['K0']*avars.dK)
        H2 = p['eta']*p['a']*avars.dP**2
        Hkeptransformed = H0 + H1 + H2
        Hrestransformed = p['eta']*p['c']*(2*avars.Psi1)**(k/2.)*np.cos(avars.theta+k*avars.psi1)

        self.assertAlmostEqual(Hkeptransformed, Hkepexpanded, delta=1.e-15) # should be exact
        self.assertAlmostEqual(Hrestransformed, Hres, delta=1.e-15) # should be exact for first order resonance (k=1)
        self.assertAlmostEqual(Hkepexpanded, Hkep, delta=(a10-1.)**2) # should match to O(da/a)^2, atrue=1, a10=a10

        #Hfinal = -p['eta']*p['Phi0']/p['tau']*(4.*avars.Phi**2 - 3.*avars.Phiprime*avars.Phi + 9./16.*avars.Phiprime**2 + (2.*avars.Phi)**(k/2.)*np.cos(avars.phi) - p['n0']*p['tau']/p['Phi0']*avars.dK*(1.-1.5*p['eta']/p['K0']*avars.dK))+ H0
        Hfinal = -p['eta']*p['Phi0']/p['tau']*(4.*(avars.Phi-avars.B)**2 + (2.*avars.Phi)**(k/2.)*np.cos(avars.phi) - p['n0']*p['tau']/p['Phi0']*avars.dK*(1.-1.5*p['eta']/p['K0']*avars.dK))+ H0
        self.assertAlmostEqual(Hfinal, Hkepexpanded+Hres, delta=1.e-15) # should be exact
Esempio n. 9
0
def populate_trio(sim, trio, pairs, jk, a10, tseries, i):
    Ns = 3
    ps = sim.particles
    for q, [label, i1, i2] in enumerate(pairs):
        e1x, e1y = ps[i1].e * np.cos(ps[i1].pomega), -ps[i1].e * np.sin(
            ps[i1].pomega)
        e2x, e2y = ps[i2].e * np.cos(ps[i2].pomega), -ps[i2].e * np.sin(
            ps[i2].pomega)
        try:
            # it's unlikely but possible for bodies to land nearly on top of  each other midtimestep and get a big kick that doesn't get caught by collisions  post timestep. All these cases are unstable, so flag them as above
            # average only affects a (Lambda) Z and I think  Zcom  don't depend on a. Zsep and Zstar slightly, but several sig figs in even when close at conjunction
            j, k = jk[label]
            avars = Andoyer.from_Simulation(sim,
                                            a10=a10[label],
                                            j=j,
                                            k=k,
                                            i1=i1,
                                            i2=i2,
                                            average=False)
            tseries[i, Ns * q + 1] = avars.Z * np.sqrt(2)  # EM = Z*sqrt(2)
            tseries[i, Ns * q + 2] = avars.Zcom  # no sqrt(2) factor
        except:  # no nearby resonance, use EM and ecom
            tseries[i, Ns * q + 1] = np.sqrt((e2x - e1x)**2 + (e2y - e1y)**2)
            tseries[i, Ns * q + 2] = np.sqrt(
                (ps[i1].m * e1x + ps[i2].m * e2x)**2 +
                (ps[i1].m * e1y + ps[i2].m * e2y)**2) / (ps[i1].m + ps[i2].m)
        try:
            j, k, tseries[i, Ns * q + 3] = find_strongest_MMR(
                sim, i1, i2
            )  # will fail if any osculating orbit is hyperbolic, flag as unstable
        except:
            return False

    tseries[i, 7] = sim.calculate_megno()  # megno

    return True