def simulation(par):
    anom, dt, e, integrator = par

    e = 1. - pow(10., e)
    dt = pow(10., dt) * torb

    rebound.reset()
    rebound.integrator = integrator
    rebound.force_is_velocitydependent = 0
    rebound.dt = dt

    rebound.add(m=1.)
    rebound.add(m=0., x=(1. - e), vy=np.sqrt((1. + e) / (1. - e)))
    particles = rebound.particles

    Ei = -1. / np.sqrt(particles[1].x * particles[1].x + particles[1].y *
                       particles[1].y + particles[1].z * particles[1].z
                       ) + 0.5 * (particles[1].vx * particles[1].vx +
                                  particles[1].vy * particles[1].vy +
                                  particles[1].vz * particles[1].vz)

    rebound.integrate(tmax, exactFinishTime=0, keepSynchronized=1)

    Ef = -1. / np.sqrt(particles[1].x * particles[1].x + particles[1].y *
                       particles[1].y + particles[1].z * particles[1].z
                       ) + 0.5 * (particles[1].vx * particles[1].vx +
                                  particles[1].vy * particles[1].vy +
                                  particles[1].vz * particles[1].vz)

    return [
        float(rebound.iter) / rebound.t * dt,
        np.fabs((Ef - Ei) / Ei) + 1e-16,
        rebound.timing / rebound.t * dt * 1e6 / 2., (Ef - Ei) / Ei
    ]
def simulation(par):
    saturn_a, saturn_e = par
    rebound.reset()
    rebound.integrator = "whfast-nocor"
    rebound.min_dt = 5.
    rebound.dt = 1.

    # These parameters are only approximately those of Jupiter and Saturn.
    sun = rebound.Particle(m=1.)
    rebound.add(sun)
    jupiter = rebound.add(primary=sun,
                          m=0.000954,
                          a=5.204,
                          anom=0.600,
                          omega=0.257,
                          e=0.048)
    saturn = rebound.add(primary=sun,
                         m=0.000285,
                         a=saturn_a,
                         anom=0.871,
                         omega=1.616,
                         e=saturn_e)

    rebound.move_to_com()
    rebound.init_megno(1e-16)
    rebound.integrate(1e3 * 2. * np.pi)

    return [
        rebound.calculate_megno(),
        1. / (rebound.calculate_lyapunov() * 2. * np.pi)
    ]  # returns MEGNO and Lypunov timescale in years
def simulation(par):
    saturn_a, saturn_e = par
    rebound.reset()
    rebound.integrator = "whfast-nocor"
    rebound.min_dt = 5.
    rebound.dt = 1.
    
    # These parameters are only approximately those of Jupiter and Saturn.
    sun     = rebound.Particle(m=1.)
    rebound.add(sun)
    jupiter = rebound.add(primary=sun,m=0.000954, a=5.204, anom=0.600, omega=0.257, e=0.048)
    saturn  = rebound.add(primary=sun,m=0.000285, a=saturn_a, anom=0.871, omega=1.616, e=saturn_e)

    rebound.move_to_com()
    rebound.init_megno(1e-16)
    rebound.integrate(1e3*2.*np.pi)

    return [rebound.calculate_megno(),1./(rebound.calculate_lyapunov()*2.*np.pi)] # returns MEGNO and Lypunov timescale in years
def simulation(par):
    anom, dt, e, integrator = par

    e = 1.-pow(10.,e)
    dt = pow(10.,dt)*torb

    rebound.reset()
    rebound.integrator = integrator
    rebound.force_is_velocitydependent = 0
    rebound.dt = dt

    rebound.add(m=1.)
    rebound.add(m=0., x=(1.-e), vy=np.sqrt((1.+e)/(1.-e)))
    particles = rebound.particles
    
    Ei = -1./np.sqrt(particles[1].x*particles[1].x+particles[1].y*particles[1].y+particles[1].z*particles[1].z) + 0.5 * (particles[1].vx*particles[1].vx+particles[1].vy*particles[1].vy+particles[1].vz*particles[1].vz)

    rebound.integrate(tmax,exactFinishTime=0,keepSynchronized=1)
    
    Ef = -1./np.sqrt(particles[1].x*particles[1].x+particles[1].y*particles[1].y+particles[1].z*particles[1].z) + 0.5 * (particles[1].vx*particles[1].vx+particles[1].vy*particles[1].vy+particles[1].vz*particles[1].vz)

    return [float(rebound.iter)/rebound.t*dt, np.fabs((Ef-Ei)/Ei)+1e-16, rebound.timing/rebound.t*dt*1e6/2., (Ef-Ei)/Ei]
def simulation(par):
    saturn_a, saturn_e = par
    rebound.reset()
    rebound.integrator = "whfast-nocor"
    rebound.dt = 5.
    
    # These parameters are only approximately those of Jupiter and Saturn.
    rebound.add(m=1.)
    rebound.add(m=0.000954, a=5.204, anom=0.600, omega=0.257, e=0.048)
    rebound.add(m=0.000285, a=saturn_a, anom=0.871, omega=1.616, e=saturn_e)

    rebound.move_to_com()
    rebound.init_megno(1e-16)
    rebound.integrate(5e2*2.*np.pi) # integrator for 500 years

    return [rebound.calculate_megno(),1./(rebound.calculat_lyapunov()*2.*np.pi)] # returns MEGNO and Lypunov timescale in years
Esempio n. 6
0
def simulation(integrator):
    print("Running "+integrator)
    with open(integrator+".txt","w") as f:
        rebound.reset()
        rebound.integrator = integrator
        rebound.dt = 0.2
            
        rebound.add(m=1.)
        rebound.add(m=0.01, a=1,e=0.1)
        rebound.add(m=0.01, a=2.)

        rebound.move_to_com()
        rebound.init_megno(1e-10)
        particles = rebound.particles
        times = np.logspace(2,5,num=1000)
        for t in times:
            rebound.integrate(t,0)
            print("%e %e %e %e %e %e %e %e\n" %(rebound.t, rebound.calculate_megno(), particles[0].x, particles[1].x, particles[2].x, particles[3].x, particles[4].x, particles[5].x),file=f)
Esempio n. 7
0
def simulation(par):
    saturn_a, saturn_e = par
    rebound.reset()
    rebound.integrator = "whfast-nocor"
    rebound.dt = 5.

    # These parameters are only approximately those of Jupiter and Saturn.
    rebound.add(m=1.)
    rebound.add(m=0.000954, a=5.204, anom=0.600, omega=0.257, e=0.048)
    rebound.add(m=0.000285, a=saturn_a, anom=0.871, omega=1.616, e=saturn_e)

    rebound.move_to_com()
    rebound.init_megno(1e-16)
    rebound.integrate(5e2 * 2. * np.pi)  # integrator for 500 years

    return [
        rebound.calculate_megno(),
        1. / (rebound.calculat_lyapunov() * 2. * np.pi)
    ]  # returns MEGNO and Lypunov timescale in years
Esempio n. 8
0
def simulation(integrator):
    print("Running " + integrator)
    with open(integrator + ".txt", "w") as f:
        rebound.reset()
        rebound.integrator = integrator
        rebound.dt = 0.2

        rebound.add(m=1.)
        rebound.add(m=0.01, a=1, e=0.1)
        rebound.add(m=0.01, a=2.)

        rebound.move_to_com()
        rebound.init_megno(1e-10)
        particles = rebound.particles
        times = np.logspace(2, 5, num=1000)
        for t in times:
            rebound.integrate(t, 0)
            print("%e %e %e %e %e %e %e %e\n" %
                  (rebound.t, rebound.calculate_megno(), particles[0].x,
                   particles[1].x, particles[2].x, particles[3].x,
                   particles[4].x, particles[5].x),
                  file=f)
# Import the rebound module
import rebound

# Add particle to rebound
rebound.add(m=1.)
rebound.add(m=1e-3, a=1., e=0.1)  # Planet 1
rebound.add(a=1.4, e=0.1)  # Massless test particle

# Output orbits in Jacobi coordinates
for o in rebound.calculate_orbits():
    print(o)

# Output orbits in Heliocentric coordinates
for o in rebound.calculate_orbits(heliocentric=True):
    print(o)

# Output cartesian coordinates
for p in rebound.particles:
    print(p)
def simulation(par):
    import rebound
    integrator, dt, run = par
    rebound.reset()
    k = 0.01720209895
    G = k * k
    rebound.G = G
    rebound.dt = dt
    rebound.integrator = integrator
    rebound.force_is_velocitydependent = 0

    rebound.add(m=1.00000597682,
                x=-4.06428567034226e-3,
                y=-6.08813756435987e-3,
                z=-1.66162304225834e-6,
                vx=+6.69048890636161e-6,
                vy=-6.33922479583593e-6,
                vz=-3.13202145590767e-9)  # Sun
    rebound.add(m=1. / 1407.355,
                x=+3.40546614227466e+0,
                y=+3.62978190075864e+0,
                z=+3.42386261766577e-2,
                vx=-5.59797969310664e-3,
                vy=+5.51815399480116e-3,
                vz=-2.66711392865591e-6)  # Jupiter
    rebound.add(m=1. / 3501.6,
                x=+6.60801554403466e+0,
                y=+6.38084674585064e+0,
                z=-1.36145963724542e-1,
                vx=-4.17354020307064e-3,
                vy=+3.99723751748116e-3,
                vz=+1.67206320571441e-5)  # Saturn
    rebound.add(m=1. / 22869.,
                x=+1.11636331405597e+1,
                y=+1.60373479057256e+1,
                z=+3.61783279369958e-1,
                vx=-3.25884806151064e-3,
                vy=+2.06438412905916e-3,
                vz=-2.17699042180559e-5)  # Uranus
    rebound.add(m=1. / 19314.,
                x=-3.01777243405203e+1,
                y=+1.91155314998064e+0,
                z=-1.53887595621042e-1,
                vx=-2.17471785045538e-4,
                vy=-3.11361111025884e-3,
                vz=+3.58344705491441e-5)  # Neptune
    N = rebound.N
    particles = rebound.particles
    np.random.seed(run)
    for i in xrange(N):
        particles[i].m *= 1. + 1e-3 * np.random.rand()
        particles[i].x *= 1. + 1e-3 * np.random.rand()
        particles[i].y *= 1. + 1e-3 * np.random.rand()
        particles[i].z *= 1. + 1e-3 * np.random.rand()
        particles[i].vx *= 1. + 1e-3 * np.random.rand()
        particles[i].vy *= 1. + 1e-3 * np.random.rand()
        particles[i].vz *= 1. + 1e-3 * np.random.rand()

    def move_to_heliocentric():
        particles[0].x = 0.
        particles[0].y = 0.
        particles[0].z = 0.
        particles[0].vx = 0.
        particles[0].vy = 0.
        particles[0].vz = 0.

    def energy():
        com_vx = 0.
        com_vy = 0.
        com_vz = 0.
        if integrator == "wh" or integrator == "mercury" or integrator[
                0:7] == "swifter":
            mtot = 0.
            for i in xrange(0, N):
                com_vx += particles[i].vx * particles[i].m
                com_vy += particles[i].vy * particles[i].m
                com_vz += particles[i].vz * particles[i].m
                mtot += particles[i].m
            com_vx /= mtot
            com_vy /= mtot
            com_vz /= mtot
        E_kin = 0.
        E_pot = 0.
        for i in xrange(N):
            dvx = particles[i].vx - com_vx
            dvy = particles[i].vy - com_vy
            dvz = particles[i].vz - com_vz
            E_kin += 0.5 * particles[i].m * (dvx * dvx + dvy * dvy + dvz * dvz)
            for j in xrange(i + 1, N):
                dx = particles[i].x - particles[j].x
                dy = particles[i].y - particles[j].y
                dz = particles[i].z - particles[j].z
                r2 = dx * dx + dy * dy + dz * dz
                E_pot -= G * particles[i].m * particles[j].m / np.sqrt(r2)
        return E_kin + E_pot

    if integrator == "wh" or integrator == "mercury" or integrator[
            0:7] == "swifter":
        move_to_heliocentric()
    else:
        rebound.move_to_com()
    ei = energy()

    runtime = 0.
    rebound.integrate(tmax, exactFinishTime=0)
    ef = energy()
    e = np.fabs((ei - ef) / ei) + 1.1e-16
    runtime += rebound.timing

    integrator, dt, run = par
    print integrator.ljust(13) + " %9.5fs" % (runtime) + "\t Error: %e" % (e)
    return [runtime, e]
Esempio n. 11
0
import rebound
import os.path

filename = "cache.bin"

solar_system_objects = [
    "Sun", "Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus",
    "Neptune", "C/2014 Q2"
]
if os.path.isfile(filename):
    rebound.load(filename)
else:
    # Get data from NASA Horizons
    rebound.add(solar_system_objects)
    rebound.move_to_com()
    # Let's save it for next time
    # Note: rebound.save() only saves the particle data, not the integrator settings, etc.
    rebound.save("cache.bin")

rebound.integrator = "whfast"
rebound.set_dt = 0.01
rebound.status()

import numpy as np
Nout = 1000
times = np.linspace(0, 16. * np.pi, Nout)  # 8 years
x = np.zeros((rebound.N, Nout))
y = np.zeros((rebound.N, Nout))

ps = rebound.particles
for ti, t in enumerate(times):
def simulation(par):
    integrator, mass = par
    rebound.reset()
    mass = pow(10., mass)
    k = 0.01720209895
    G = k * k
    rebound.G = G
    rebound.dt = 0.
    rebound.integrator = integrator

    rebound.add(m=1.00000597682,
                x=-4.06428567034226e-3,
                y=-6.08813756435987e-3,
                z=-1.66162304225834e-6,
                vx=+6.69048890636161e-6,
                vy=-6.33922479583593e-6,
                vz=-3.13202145590767e-9)  # Sun
    rebound.add(m=mass,
                x=+3.40546614227466e+0,
                y=+3.62978190075864e+0,
                z=+3.42386261766577e-2,
                vx=-5.59797969310664e-3,
                vy=+5.51815399480116e-3,
                vz=-2.66711392865591e-6)  # Jupiter
    rebound.add(m=mass,
                x=+6.60801554403466e+0,
                y=+6.38084674585064e+0,
                z=-1.36145963724542e-1,
                vx=-4.17354020307064e-3,
                vy=+3.99723751748116e-3,
                vz=+1.67206320571441e-5)  # Saturn
    rebound.add(m=mass,
                x=+1.11636331405597e+1,
                y=+1.60373479057256e+1,
                z=+3.61783279369958e-1,
                vx=-3.25884806151064e-3,
                vy=+2.06438412905916e-3,
                vz=-2.17699042180559e-5)  # Uranus
    rebound.add(m=mass,
                x=-3.01777243405203e+1,
                y=+1.91155314998064e+0,
                z=-1.53887595621042e-1,
                vx=-2.17471785045538e-4,
                vy=-3.11361111025884e-3,
                vz=+3.58344705491441e-5)  # Neptune
    N = rebound.N

    def move_to_heliocentric():
        particles = rebound.particles

        for i in xrange(1, N):
            particles[i].x -= particles[0].x
            particles[i].y -= particles[0].y
            particles[i].z -= particles[0].z
            particles[i].vx -= particles[0].vx
            particles[i].vy -= particles[0].vy
            particles[i].vz -= particles[0].vz
        particles[0].x = 0.
        particles[0].y = 0.
        particles[0].z = 0.
        particles[0].vx = 0.
        particles[0].vy = 0.
        particles[0].vz = 0.

    def energy():
        if integrator == "wh":
            rebound.move_to_com()
        particles = rebound.particles
        E_kin = 0.
        E_pot = 0.
        for i in xrange(N):
            E_kin += 0.5 * particles[i].m * (
                particles[i].vx * particles[i].vx + particles[i].vy *
                particles[i].vy + particles[i].vz * particles[i].vz)
            for j in xrange(i + 1, N):
                dx = particles[i].x - particles[j].x
                dy = particles[i].y - particles[j].y
                dz = particles[i].z - particles[j].z
                r2 = dx * dx + dy * dy + dz * dz
                E_pot -= G * particles[i].m * particles[j].m / np.sqrt(r2)
        if integrator == "wh":
            move_to_heliocentric()
        return E_kin + E_pot

    rebound.move_to_com()
    ei = energy()

    es = 1e-20

    for s in xrange(1000):
        rebound.step()
        ef = energy()
        e = np.fabs((ei - ef) / ei)
        es = max(es, e)

    return es
Esempio n. 13
0
def simulation(par):
    import rebound
    integrator, dt, run = par
    rebound.reset()
    k = 0.01720209895    
    G = k*k
    rebound.G = G     
    rebound.dt = dt
    if integrator == "whfast-nocor":
        integrator = "whfast"
    else:
        rebound.integrator_whfast_corrector = 11
    rebound.integrator = integrator
    rebound.force_is_velocitydependent = 0

    rebound.add(m=1.00000597682, x=-4.06428567034226e-3, y=-6.08813756435987e-3, z=-1.66162304225834e-6, vx=+6.69048890636161e-6, vy=-6.33922479583593e-6, vz=-3.13202145590767e-9)   # Sun
    rebound.add(m=1./1407.355,   x=+3.40546614227466e+0, y=+3.62978190075864e+0, z=+3.42386261766577e-2, vx=-5.59797969310664e-3, vy=+5.51815399480116e-3, vz=-2.66711392865591e-6)   # Jupiter
    rebound.add(m=1./3501.6,     x=+6.60801554403466e+0, y=+6.38084674585064e+0, z=-1.36145963724542e-1, vx=-4.17354020307064e-3, vy=+3.99723751748116e-3, vz=+1.67206320571441e-5)   # Saturn
    rebound.add(m=1./22869.,     x=+1.11636331405597e+1, y=+1.60373479057256e+1, z=+3.61783279369958e-1, vx=-3.25884806151064e-3, vy=+2.06438412905916e-3, vz=-2.17699042180559e-5)   # Uranus
    rebound.add(m=1./19314.,     x=-3.01777243405203e+1, y=+1.91155314998064e+0, z=-1.53887595621042e-1, vx=-2.17471785045538e-4, vy=-3.11361111025884e-3, vz=+3.58344705491441e-5)   # Neptune
    N = rebound.N
    particles = rebound.particles
    np.random.seed(run)
    for i in xrange(N):
        particles[i].m *= 1.+1e-3*np.random.rand()
        particles[i].x *= 1.+1e-3*np.random.rand()
        particles[i].y *= 1.+1e-3*np.random.rand()
        particles[i].z *= 1.+1e-3*np.random.rand()
        particles[i].vx *= 1.+1e-3*np.random.rand()
        particles[i].vy *= 1.+1e-3*np.random.rand()
        particles[i].vz *= 1.+1e-3*np.random.rand()

    def move_to_heliocentric():
        particles[0].x  = 0.
        particles[0].y  = 0. 
        particles[0].z  = 0. 
        particles[0].vx = 0. 
        particles[0].vy = 0. 
        particles[0].vz = 0. 


    def energy():
        com_vx = 0.
        com_vy = 0.
        com_vz = 0.
        if integrator=="wh" or integrator=="mercury" or integrator[0:7]=="swifter":
            mtot = 0.
            for i in xrange(0,N):
                com_vx += particles[i].vx*particles[i].m 
                com_vy += particles[i].vy*particles[i].m 
                com_vz += particles[i].vz*particles[i].m 
                mtot += particles[i].m
            com_vx /= mtot
            com_vy /= mtot
            com_vz /= mtot
        E_kin = 0.
        E_pot = 0.
        for i in xrange(N):
            dvx = particles[i].vx - com_vx
            dvy = particles[i].vy - com_vy
            dvz = particles[i].vz - com_vz
            E_kin += 0.5*particles[i].m*(dvx*dvx + dvy*dvy + dvz*dvz)
            for j in xrange(i+1,N):
                dx = particles[i].x-particles[j].x
                dy = particles[i].y-particles[j].y
                dz = particles[i].z-particles[j].z
                r2 = dx*dx + dy*dy + dz*dz
                E_pot -= G*particles[i].m*particles[j].m/np.sqrt(r2)
        return E_kin+E_pot

    if integrator=="wh" or integrator=="mercury" or integrator[0:7]=="swifter":
        move_to_heliocentric()
    else:
        rebound.move_to_com()
    ei = energy()


    runtime = 0.
    rebound.integrate(tmax,exact_finish_time=0)
    ef = energy()
    e = np.fabs((ei-ef)/ei)+1.1e-16
    runtime += rebound.timing
    
    integrator, dt, run = par
    print integrator.ljust(13) + " %9.5fs"%(runtime) + "\t Error: %e"  %( e)
    return [runtime, e]
Esempio n. 14
0
def simulation(par):
    integrator, mass = par
    rebound.reset()
    mass = pow(10.,mass)
    k = 0.01720209895    
    G = k*k
    rebound.G = G     
    rebound.dt = 0.
    rebound.integrator = integrator

    rebound.add(m=1.00000597682, x=-4.06428567034226e-3, y=-6.08813756435987e-3, z=-1.66162304225834e-6, vx=+6.69048890636161e-6, vy=-6.33922479583593e-6, vz=-3.13202145590767e-9)   # Sun
    rebound.add(m=mass,   x=+3.40546614227466e+0, y=+3.62978190075864e+0, z=+3.42386261766577e-2, vx=-5.59797969310664e-3, vy=+5.51815399480116e-3, vz=-2.66711392865591e-6)   # Jupiter
    rebound.add(m=mass,     x=+6.60801554403466e+0, y=+6.38084674585064e+0, z=-1.36145963724542e-1, vx=-4.17354020307064e-3, vy=+3.99723751748116e-3, vz=+1.67206320571441e-5)   # Saturn
    rebound.add(m=mass,     x=+1.11636331405597e+1, y=+1.60373479057256e+1, z=+3.61783279369958e-1, vx=-3.25884806151064e-3, vy=+2.06438412905916e-3, vz=-2.17699042180559e-5)   # Uranus
    rebound.add(m=mass,     x=-3.01777243405203e+1, y=+1.91155314998064e+0, z=-1.53887595621042e-1, vx=-2.17471785045538e-4, vy=-3.11361111025884e-3, vz=+3.58344705491441e-5)   # Neptune
    N = rebound.N

    def move_to_heliocentric():
        particles = rebound.particles
        
        for i in xrange(1,N):
            particles[i].x -= particles[0].x
            particles[i].y -= particles[0].y
            particles[i].z -= particles[0].z
            particles[i].vx -= particles[0].vx
            particles[i].vy -= particles[0].vy
            particles[i].vz -= particles[0].vz
        particles[0].x  = 0.
        particles[0].y  = 0. 
        particles[0].z  = 0. 
        particles[0].vx = 0. 
        particles[0].vy = 0. 
        particles[0].vz = 0. 


    def energy():
        if integrator=="wh":
            rebound.move_to_com()
        particles = rebound.particles
        E_kin = 0.
        E_pot = 0.
        for i in xrange(N):
            E_kin += 0.5*particles[i].m*(particles[i].vx*particles[i].vx + particles[i].vy*particles[i].vy + particles[i].vz*particles[i].vz)
            for j in xrange(i+1,N):
                dx = particles[i].x-particles[j].x
                dy = particles[i].y-particles[j].y
                dz = particles[i].z-particles[j].z
                r2 = dx*dx + dy*dy + dz*dz
                E_pot -= G*particles[i].m*particles[j].m/np.sqrt(r2)
        if integrator=="wh":
            move_to_heliocentric()
        return E_kin+E_pot

    rebound.move_to_com()
    ei = energy()

    es = 1e-20

    for s in xrange(1000):
        rebound.step()
        ef = energy()
        e = np.fabs((ei-ef)/ei)
        es = max(es,e)

    return es
# Import the rebound module
import rebound

# Add particles
# We work in units where G=1.
rebound.add(m=1.)  # Test particle
rebound.add(m=1e-3, x=1., vy=1.)  # Planet

# Move particles so that the center of mass is (and stays) at the origin
rebound.move_to_com()

# You can provide a function, written in python to REBOUND.
# This function gets called every time the forces are evaluated.
# Simple add any any additional (non-gravitational) forces to the
# particle accelerations. Here, we add a simple drag force. This
# will make the planet spiral into the star.
ps = rebound.particles


def dragforce():
    dragcoefficient = 1e-2
    for p in ps:
        p.ax += -dragcoefficient * p.vx
        p.ay += -dragcoefficient * p.vy
        p.az += -dragcoefficient * p.vz


# Tell rebound which function to call
rebound.additional_forces = dragforce

# Integrate until t=100 (roughly 16 orbits at 1 AU)
Esempio n. 16
0
import rebound
import os.path

filename = "cache.bin"

solar_system_objects = ["Sun", "Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "C/2014 Q2"]
if os.path.isfile(filename):
    rebound.load(filename)
else: 
    # Get data from NASA Horizons
    rebound.add(solar_system_objects)
    rebound.move_to_com()
    # Let's save it for next time
    # Note: rebound.save() only saves the particle data, not the integrator settings, etc.
    rebound.save("cache.bin")  

rebound.set_integrator("whfast")
rebound.set_dt(0.01)
rebound.status()

import numpy as np
Nout = 1000
times = np.linspace(0,16.*np.pi,Nout) # 8 years
N = rebound.get_N()
x = np.zeros((N,Nout))
y = np.zeros((N,Nout))

p = rebound.get_particles()
for ti,t in enumerate(times):
    rebound.integrate(t)
    for i in xrange(0,N):
import rebound

# Add a particle at the origin with mass 1
rebound.add(m=1.)  

# Add a particle with mass 1e-3 on a Keplerian 
# orbit around the center of mass (including all 
# particles added so far) with semi-major axis 1
rebound.add(m=1e-3, a=1.)

# Add a test particle (mass=0) on a Keplerian orbit 
# around the center of mass (both particles added above)
# with a semi-major axis of 2 and eccentricity of 0.1.
# This corresponds to Jacobi coordinates.
rebound.add(a=1., e=0.1)

# Move all particles to the-center-of-momentum frame.
rebound.move_to_com()

# Print the resulting cartesian coordinates.
for p in rebound.particles:
    print(p.m, p.x, p.y, p.z, p.vx, p.vy, p.vz)

# Integrate for 100 time units
rebound.integrate(100.)

Esempio n. 18
0
# Import the rebound module
import rebound

# Add particles
# We work in units where G=1.  
rebound.add(m=1. )                  # Test particle
rebound.add(m=1e-3,x=1.,vy=1. )     # Planet

# Move particles so that the center of mass is (and stays) at the origin  
rebound.move_to_com()

# You can provide a function, written in python to REBOUND.
# This function gets called every time the forces are evaluated.
# Simple add any any additional (non-gravitational) forces to the 
# particle accelerations. Here, we add a simple drag force. This 
# will make the planet spiral into the star.
ps = rebound.particles
def dragforce():
    dragcoefficient = 1e-2
    for p in ps:
        p.ax += -dragcoefficient * p.vx
        p.ay += -dragcoefficient * p.vy
        p.az += -dragcoefficient * p.vz

# Tell rebound which function to call
rebound.additional_forces = dragforce

# Integrate until t=100 (roughly 16 orbits at 1 AU) 
rebound.integrate(100.)

# Output something at the end (the planet will be at ~0.1 AU)
Esempio n. 19
0
import rebound
import reboundxf
import numpy as np 

rebound.integrator = "ias15"
rebound.G = 4*np.pi**2
tmax = 1.e4 # years

rebound.add(m=1.)
rebound.add(m=1e-6,a=1.,e=0.5)
#rebound.add(m=1e-6,a=2.,e=0.5)
rebound.move_to_com() # Moves to the center of momentum frame

rebound.additional_forces = reboundxf.forces()
reboundxf.set_e_damping([0.,tmax/10.])#,tmax])
reboundxf.set_migration([0.,0.])#,tmax])

Nout = 1000
e1,e2,a1,a2 = np.zeros(Nout), np.zeros(Nout), np.zeros(Nout), np.zeros(Nout)
times = np.linspace(0.,tmax,Nout)
for i,time in enumerate(times):
    rebound.integrate(time)
    orbits = rebound.calculate_orbits()
    e1[i] = orbits[0].e
    #e2[i] = orbits[1].e
    a1[i] = orbits[0].a
    #a2[i] = orbits[1].a

import matplotlib.pyplot as plt
fig = plt.figure(figsize=(15,5))
ax = plt.subplot(111)
Esempio n. 20
0
# Import the rebound module
import rebound

# Set variables (defaults are G=1, t=0, dt=0.01)
k = 0.01720209895  # Gaussian constant
rebound.G = k * k  # Gravitational constant

# Setup particles (data taken from NASA Horizons)
# This could also be easily read in from a file.
rebound.add(m=1.00000597682,
            x=-4.06428567034226e-3,
            y=-6.08813756435987e-3,
            z=-1.66162304225834e-6,
            vx=+6.69048890636161e-6,
            vy=-6.33922479583593e-6,
            vz=-3.13202145590767e-9)  # Sun
rebound.add(m=1. / 1047.355,
            x=+3.40546614227466e+0,
            y=+3.62978190075864e+0,
            z=+3.42386261766577e-2,
            vx=-5.59797969310664e-3,
            vy=+5.51815399480116e-3,
            vz=-2.66711392865591e-6)  # Jupiter
rebound.add(m=1. / 3501.6,
            x=+6.60801554403466e+0,
            y=+6.38084674585064e+0,
            z=-1.36145963724542e-1,
            vx=-4.17354020307064e-3,
            vy=+3.99723751748116e-3,
            vz=+1.67206320571441e-5)  # Saturn
rebound.add(m=1. / 22869.,
Esempio n. 21
0
# Import the rebound module
import rebound

# Add particle to rebound
rebound.add( m=1. )                
rebound.add( m=1e-3, a=1., e=0.1 ) # Planet 1
rebound.add( a=1.4, e=0.1 )       # Massless test particle

# Output orbits in Jacobi coordinates
for o in rebound.calculate_orbits(): print(o)

# Output orbits in Heliocentric coordinates
for o in rebound.calculate_orbits(heliocentric=True): print(o)

# Output cartesian coordinates
for p in rebound.particles: 
    print(p)
Esempio n. 22
0
def migr(para):

    isma = para[0]
    fsma = para[1]
    tmax = para[2]

    model='MigaIVa'
    integrator='ias15'

    VarOut = [['a','e','Omega','omega','l'],['x','y','z']]

    tau = tmax/np.log(isma/fsma)
    Nout = 1001

    itg.InitRebound(integrator)

    itg.AddPlanets(model)
    rebound.add( m=1e-3, a=isma, e=0.05, inc=89.*np.pi/180. )  #Jup1

    itg.ArrangeSys()

    dtb.InitOrbElem2(VarOut,Nout,tmax)

    migration(7,tau)

    dtb.Destab(tmax,VarOut,Nout)

    Nout = len(cfg.times)

    itg.PlotLatex()
    Phi = phi.calcPhi(Nout)
    phi.Plot_phi(isma,Phi,'Phi')
    
    times = np.reshape(cfg.times,[1,Nout])
    OrbElem = np.concatenate((times,cfg.a,cfg.e))
    Coord = np.concatenate((times,cfg.x,cfg.y,cfg.z))
    Phi = np.concatenate((times,cfg.Omega,cfg.omega,cfg.l))

    itg.Print2File(OrbElem,
                     'tmax'+str(int(tmax))+'_tau'+str(int(tau))+'_'
                     +str(int(isma))+'_OrbElem')
    itg.Print2File(Coord,
                     'tmax'+str(int(tmax))+'_tau'+str(int(tau))+'_'
                     +str(int(isma))+'_Coord')
    itg.Print2File(Coord,
                     'tmax'+str(int(tmax))+'_tau'+str(int(tau))+'_'
                     +str(int(isma))+'_Phi')

    
    strSMA = str(isma).replace('.','_')

    itg.PlotvTime(cfg.a,'Semi-Major Axis (AU)',Title=str(isma),
                  save=True,File='plots/'+strSMA+'/sma.png')
    itg.PlotvTime(cfg.e,'Eccentricity',Title=str(isma),save=True,
                  File='plots/'+strSMA+'/ecc.png')
    
    plt.figure()
    plt.xlabel('Time (yr)')
    plt.ylabel('Semi-Major Axis (AU)')
    plt.title(str(isma))
    
    for Planet in range(cfg.NumPlanet-1):
        plt.plot(cfg.times,cfg.a[Planet],
                 color=cfg.Colours[Planet],label=cfg.Names[Planet])
    plt.legend()
    plt.savefig('plots/'+strSMA+'/sma_zoom.png')

    plt.show()
Esempio n. 23
0
for times in tmax:
    rebound.reset()

    # Set up the integrator
    #---------------------------------------------------------------------

    rebound.dt=0.1*np.sqrt(0.09100**3) 
    rebound.integrator='whfast'
    rebound.G=4.*np.pi**2

    # Add particles
    #---------------------------------------------------------------------

    K11 = rebound.Particle( m=0.950 )
    rebound.add( K11 )

    rebound.add( primary=K11, m=5.70467e-6, a=0.09100, e=0.045, anom=0 )  #K11b
    rebound.add( primary=K11, m=8.70713e-6, a=0.10700, e=0.026, anom=0 )  #K11c
    rebound.add( primary=K11, m=2.19179e-5, a=0.15500, e=0.004, anom=0 )  #K11d
    rebound.add( primary=K11, m=2.40197e-5, a=0.19500, e=0.012, anom=0 )  #K11e
    rebound.add( primary=K11, m=6.00492e-6, a=0.25000, e=0.013, anom=0 )  #K11f
    rebound.add( primary=K11, m=7.50615e-5, a=0.46600, e=0., anom=0 )  #K11g
    rebound.add( primary=K11, m=1.00000e-3, a=5.00000, e=0.050, anom=np.random.rand(1) )  #K11Jup1
    rebound.add( primary=K11, m=1.00000e-3, a=7.50000, e=0.036, anom=np.random.rand(1))  #K11Jup2
   
    rebound.move_to_com()
    ps = rebound.particles
    print str(times)+':'
    time1 = time.time()
    rebound.integrate(times)