Ejemplo n.º 1
0
def Pythagorean_initial_conditions():
    """ 
    Initial conditions for the Pythagorean system, from:
        amuse/sandbox/spz/Pythagorean.py
    """

    stars = datamodel.Stars(3)

    unit_velocity = nbody_system.length / nbody_system.time
    star0 = stars[0]
    star0.mass = 3.0 | nbody_system.mass
    star0.position = [1, 3, 0] | nbody_system.length
    star0.velocity = [0, 0, 0] | unit_velocity
    star0.radius = 0.0 | nbody_system.length

    star1 = stars[1]
    star1.mass = 4.0 | nbody_system.mass
    star1.position = [-2, -1, 0] | nbody_system.length
    star1.velocity = [0, 0, 0] | unit_velocity
    star1.radius = 0.0 | nbody_system.length

    star2 = stars[2]
    star2.mass = 5.0 | nbody_system.mass
    star2.position = [1, -1, 0] | nbody_system.length
    star2.velocity = [0, 0, 0] | unit_velocity
    star2.radius = 0.0 | nbody_system.length

    return stars
Ejemplo n.º 2
0
    def test3(self):
        convert_nbody = nbody_system.nbody_to_si(1.0 | units.MSun,
                                                 149.5e6 | units.km)

        instance = Huayno(convert_nbody)
        instance.initialize_code()
        instance.parameters.epsilon_squared = 0.00001 | units.AU**2

        stars = datamodel.Stars(2)
        star1 = stars[0]
        star2 = stars[1]

        star1.mass = units.MSun(1.0)
        star1.position = units.AU(numpy.array((-1.0, 0.0, 0.0)))
        star1.velocity = units.AUd(numpy.array((0.0, 0.0, 0.0)))
        star1.radius = units.RSun(1.0)

        star2.mass = units.MSun(1.0)
        star2.position = units.AU(numpy.array((1.0, 0.0, 0.0)))
        star2.velocity = units.AUd(numpy.array((0.0, 0.0, 0.0)))
        star2.radius = units.RSun(100.0)

        instance.particles.add_particles(stars)

        for x in range(1, 2000, 10):
            instance.evolve_model(x | units.day)
            instance.particles.copy_values_of_all_attributes_to(stars)
            stars.savepoint()
Ejemplo n.º 3
0
    def __init__(self):
        self.load_integrator_and_units()
        self.planets = []
        self.planets_data = Horizons()

        #Notable events
        self.start_date = date(1971, 10, 26)
        self.voyagerI_launch_date = date(1977, 9, 7)
        self.stop_date = date(1989, 10, 26)

        self.model_t0 = self.start_date

        self.planets = datamodel.Stars(10)
        self.voyagerI = datamodel.Particle()

        #set I.C. using Horizons database
        self.set_IC_at_date([self.planets_data.Sun, self.planets_data.Mercury, self.planets_data.Venus, 
                             self.planets_data.Earth, self.planets_data.Moon, self.planets_data.Mars, 
                             self.planets_data.Jupiter, self.planets_data.Saturn, self.planets_data.Uranus,
                             self.planets_data.Neptune], 
                            self.planets,
                            self.start_date)

        self.set_IC_at_date([self.planets_data.VoyagerI],self.voyagerI.as_set(), self.voyagerI_launch_date)

        self.planets.synchronize_to(self.code.particles)

        self.planets_from_code_to_model = self.code.particles.new_channel_to(self.planets)

        #later we will add particles
        self.all_particles = self.planets.copy()

        self.P = planetarium.SolarSystemView((1600,1000))
Ejemplo n.º 4
0
def binary_with_neighbours_initial_conditions():
    """
    ad-hoc binary at origin and two stars far away on nearly circular orbit
    orbital period: roughly 200
    """
    from amuse.support.data import core
    from amuse.units import nbody_system
    a = 10
    e = 0.9
    G = 1
    m1 = 0.5
    m2 = 0.5
    mu = G * (m1 + m2)
    h = -0.5 * mu / a
    X = 0.5 * a * (1 - e)
    V = 0.5 * math.sqrt(-h)
    #V = 0.5 * math.sqrt( 2 * mu * ( 1 / (a * (1 - e))  - 1 / (2 * a) ) )
    x = []
    x.append([+X, 0, 0])
    x.append([-X, 0, 0])
    v = []
    v.append([0, -V, 0])
    v.append([0, +V, 0])
    x.append([+20 * X, 0, 0])
    x.append([-20 * X, 0, 0])
    v.append([0, -3 * V, 0])
    v.append([0, +3 * V, 0])
    stars = datamodel.Stars(len(x))
    for i in range(len(stars)):
        star = stars[i]
        star.mass = 0.5 | nbody_system.mass
        star.position = x[i] | nbody_system.length
        star.velocity = v[i] | (nbody_system.length / nbody_system.time)
        star.radius = 0. | nbody_system.length  # obligatory for Hermite() integrator
    return stars
Ejemplo n.º 5
0
def setup_particle_system(n_dust):
    stars = datamodel.Stars(n_dust)
    generate_dust(stars)

    sun = stars[0]
    sun.mass = 1.0 | units.MSun
    sun.position = units.m(np.array((0.0, 0.0, 0.0)))
    sun.velocity = units.ms(np.array((0.0, 0.0, 0.0)))
    sun.radius = 0.1000 | units.RSun

    #earth = stars[1]
    #earth.mass = units.kg(5.9736e24)
    #earth.position = units.AU(np.array((8.418982185410142E-01,  5.355823303978186E-01,  2.327960005926782E-05)))
    #earth.velocity = units.AUd(np.array((-9.488931818313919E-03,  1.447515189957170E-02,  3.617712172296458E-07)))
    #earth.radius = 6000 | units.km

    jupiter = stars[1]
    jupiter.mass = 1.8986e27 | units.kg  #
    jupiter.position = units.AU(
        np.array((-1.443168153922270E+00, -5.114454902835615E+00,
                  5.340409708180518E-02)))
    jupiter.velocity = units.AUd(
        np.array((7.173114487727194E-03, -1.699488558889569E-03,
                  -1.537231526125508E-04)))
    jupiter.radius = 20000 | units.km

    return stars, sun, jupiter
Ejemplo n.º 6
0
def particles_from_floats(m, x, v):
    stars = datamodel.Stars(len(x))
    for i in range(len(stars)):
        star = stars[i]
        star.mass = m[i] | nbody_system.mass
        star.position = x[i] | nbody_system.length
        star.velocity = v[i] | (nbody_system.length / nbody_system.time)
        star.radius = 0. | nbody_system.length  # obligatory for Hermite() integrator
    return stars
Ejemplo n.º 7
0
    def test2(self):
        #not completed
        convert_nbody = nbody_system.nbody_to_si(1.0 | units.MSun,
                                                 149.5e6 | units.km)

        instance = BHTree(convert_nbody)
        #instance.dt_dia = 1
        instance.parameters.epsilon_squared = 0.001 | units.AU**2
        #instance.timestep = 0.0001
        #instance.use_self_gravity = 0
        instance.commit_parameters()

        stars = datamodel.Stars(2)
        sun = stars[0]
        sun.mass = units.MSun(1.0)
        sun.position = units.m(numpy.array((0.0, 0.0, 0.0)))
        sun.velocity = units.ms(numpy.array((0.0, 0.0, 0.0)))
        sun.radius = units.RSun(1.0)

        earth = stars[1]
        earth.mass = units.kg(5.9736e24)
        earth.radius = units.km(6371)
        earth.position = units.km(numpy.array((149.5e6, 0.0, 0.0)))
        earth.velocity = units.ms(numpy.array((0.0, 29800, 0.0)))

        instance.particles.add_particles(stars)
        instance.commit_particles()
        self.assertAlmostRelativeEquals(sun.radius,
                                        instance.particles[0].radius)

        for x in range(1, 2000, 10):
            instance.evolve_model(x | units.day)
            instance.particles.copy_values_of_all_attributes_to(stars)
            stars.savepoint()

        if HAS_MATPLOTLIB:
            figure = pyplot.figure()
            plot = figure.add_subplot(1, 1, 1)

            x_points = earth.get_timeline_of_attribute("x")
            y_points = earth.get_timeline_of_attribute("y")

            x_points_in_AU = map(lambda (t, x): x.value_in(units.AU), x_points)
            y_points_in_AU = map(lambda (t, x): x.value_in(units.AU), y_points)

            plot.scatter(x_points_in_AU, y_points_in_AU, color="b", marker='o')

            plot.set_xlim(-1.5, 1.5)
            plot.set_ylim(-1.5, 1.5)

            test_results_path = self.get_path_to_results()
            output_file = os.path.join(test_results_path,
                                       "bhtree-earth-sun.svg")
            figure.savefig(output_file)

        instance.cleanup_code()
        instance.stop()
Ejemplo n.º 8
0
    def test1(self):
        convert_nbody = nbody_system.nbody_to_si(1.0 | units.MSun,
                                                 149.5e6 | units.km)

        instance = BHTree(convert_nbody)
        instance.parameters.epsilon_squared = 0.001 | units.AU**2

        stars = datamodel.Stars(2)

        sun = stars[0]
        sun.mass = units.MSun(1.0)
        sun.position = [0.0, 0.0, 0.0] | units.m
        sun.velocity = [0.0, 0.0, 0.0] | units.ms
        sun.radius = units.RSun(1.0)

        earth = stars[1]
        earth.mass = units.kg(5.9736e24)
        earth.radius = units.km(6371)
        earth.position = [149.5e6, 0.0, 0.0] | units.km
        earth.velocity = [0.0, 29800, 0.0] | units.ms

        #instance.particles.add_particles(stars)
        instance.particles.add_particles(stars)

        postion_at_start = earth.position.value_in(units.AU)[0]

        instance.evolve_model(365.0 | units.day)
        instance.particles.copy_values_of_all_attributes_to(stars)

        postion_after_full_rotation = earth.position.value_in(units.AU)[0]

        self.assertAlmostEqual(postion_at_start, postion_after_full_rotation,
                               3)

        instance.evolve_model(365.0 + (365.0 / 2) | units.day)

        instance.particles.copy_values_of_all_attributes_to(stars)

        postion_after_half_a_rotation = earth.position.value_in(units.AU)[0]
        self.assertAlmostEqual(-postion_at_start,
                               postion_after_half_a_rotation, 2)

        instance.evolve_model(365.0 + (365.0 / 2) + (365.0 / 4) | units.day)

        instance.particles.copy_values_of_all_attributes_to(stars)

        postion_after_half_a_rotation = earth.position.value_in(units.AU)[1]

        self.assertAlmostEqual(-postion_at_start,
                               postion_after_half_a_rotation, 1)
        instance.cleanup_code()
        instance.stop()
Ejemplo n.º 9
0
    def new_system_of_sun_and_earth(self):
        stars = datamodel.Stars(2)
        sun = stars[0]
        sun.mass = units.MSun(1.0)
        sun.position = units.m(np.array((0.0, 0.0, 0.0)))
        sun.velocity = units.ms(np.array((0.0, 0.0, 0.0)))
        sun.radius = units.RSun(1.0)

        earth = stars[1]
        earth.mass = units.kg(5.9736e24)
        earth.radius = units.km(6371)
        earth.position = units.km(np.array((149.5e6, 0.0, 0.0)))
        earth.velocity = units.ms(np.array((0.0, 29800, 0.0)))

        return stars
Ejemplo n.º 10
0
def plummer_with_planets_initial_conditions(n=128,
                                            frac_planets=0.5,
                                            m_star=None,
                                            m_planet=10e-10,
                                            a_planet=0.001,
                                            e_planet=0.5,
                                            v=False):
    stars = new_plummer_sphere(n)
    # print average distance between stars
    if v:
        avg_star_dist = 0.0
        for stari in stars:
            for starj in stars:
                if stari != starj:
                    dvec = (starj.position - stari.position).value_in(
                        nbu.length)
                    d = math.sqrt(dvec[0]**2 + dvec[1]**2 + dvec[2]**2)
                    avg_star_dist = avg_star_dist + d / len(stars)
        print "Average distance between stars: %f, semi-major axis: %f" % (
            avg_star_dist, a_planet)

    # normalize "integration work per planetary system", attempt #2
    if not (m_star is None):
        for star in stars:
            star.mass = m_star | nbu.mass
    planets = datamodel.Stars(int(frac_planets * n))
    for (star, planet) in zip(stars, planets):
        adj = two_body_initial_conditions(star.mass.value_in(nbu.mass),
                                          m_planet, a_planet, e_planet)
        planet.position = star.position + adj[1].position
        star.position = star.position + adj[0].position
        planet.velocity = star.velocity + adj[1].velocity
        star.velocity = star.velocity + adj[0].velocity
        # hack, remove
        #star.mass = (1 / float(n)) | nbu.mass
        planet.mass = m_planet | nbu.mass
        planet.radius = 0. | nbu.length
        sys_orbital_period = two_body_orbital_period(
            star.mass.value_in(nbu.mass), planet.mass.value_in(nbu.mass),
            a_planet, e_planet)
        if v: print "Orbital period: %f" % (sys_orbital_period, )
    stars.add_particles(planets)
    if v:
        print "All particles (first n/2: stars, second n/2: planets)"
        print stars
    return stars
Ejemplo n.º 11
0
    def new_system_of_sun_and_earth_and_moon(self):
        stars = datamodel.Stars(3)
        sun = stars[0]
        sun.mass = units.MSun(1.0)
        sun.position = units.m(numpy.array((0.0, 0.0, 0.0)))
        sun.velocity = units.ms(numpy.array((0.0, 0.0, 0.0)))
        sun.radius = units.RSun(1.0)

        earth = stars[1]
        earth.mass = units.kg(5.9736e24)
        earth.radius = units.km(6371)
        earth.position = units.km(numpy.array((149.5e6, 0.0, 0.0)))
        earth.velocity = units.ms(numpy.array((0.0, 29800, 0.0)))

        moon = stars[2]
        moon.mass = units.kg(7.3477e22)
        moon.radius = units.km(1737.10)
        moon.position = units.km(numpy.array((149.5e6 + 384399.0, 0.0, 0.0)))
        moon.velocity = ([0.0, 1.022, 0] | units.km / units.s) + earth.velocity
        return stars
Ejemplo n.º 12
0
    def test3(self):
        convert_nbody = nbody_system.nbody_to_si(1.0 | units.MSun,
                                                 149.5e6 | units.km)

        instance = BHTree(convert_nbody)
        #instance.dt_dia = 1
        instance.parameters.epsilon_squared = 0.001 | units.AU**2
        #instance.timestep = 0.0001
        #instance.use_self_gravity = 0
        instance.commit_parameters()

        stars = datamodel.Stars(2)
        star1 = stars[0]
        star2 = stars[1]

        star1.mass = units.MSun(1.0)
        star1.position = units.AU(numpy.array((-.10, 0.0, 0.0)))
        star1.velocity = units.AUd(numpy.array((0.0, 0.0, 0.0)))
        star1.radius = units.RSun(1.0)

        star2.mass = units.MSun(1.0)
        star2.position = units.AU(numpy.array((.10, 0.0, 0.0)))
        star2.velocity = units.AUd(numpy.array((0.0, 0.0, 0.0)))
        star2.radius = units.RSun(100.0)

        instance.particles.add_particles(stars)
        instance.commit_particles()

        for x in range(1, 200, 1):
            instance.evolve_model(x | units.day)
            instance.particles.copy_values_of_all_attributes_to(stars)
            #instance.get_indices_of_colliding_particles()
            #print stars[0].position-stars[1].position
            stars.savepoint()

        instance.cleanup_code()
        instance.stop()
Ejemplo n.º 13
0
            stars.savepoint(x)

        #self.instance.cleanup_module()
        #del instance we do that somewhere else...

    def cleanup(self):
        del self.instance


if __name__ == '__main__':

    I = SolarSystemModel()

    #make bodies in mem
    I.stars = datamodel.Stars(10)

    bodies = [
        I.Sun, I.Mercury, I.Venus, I.Earth, I.Moon, I.Mars, I.Jupiter,
        I.Saturn, I.Uranus, I.Neptune
    ]

    #set IC for bodies in mem according to data set and date
    for i, body in enumerate(bodies):

        I.stars[i].mass = body.mass
        I.stars[i].radius = body.radius
        r, v = body.get_vectors_at_date(date(1971, 10, 26))
        I.stars[i].position = units.AU(array((r[0], r[1], r[2])))
        I.stars[i].velocity = units.AUd(array((v[0], v[1], v[2])))
Ejemplo n.º 14
0
            r, v = i.get_vectors_at_date(self.days)
            R.append([0.05, r[0], r[1], r[2]])

        self.omega += 0.05
        self.render(R)


if __name__ == "__main__":

    nstars = 1  #int(sys.argv[1])
    workers = 1  #int(sys.argv[2])
    method = 'hermite'  # sys.argv[3]
    print nstars
    seed = None

    stars = datamodel.Stars(3)
    earth = stars[0]
    earth.mass = units.kg(5.9736e24)
    earth.position = units.m(np.array((0.0, 0.0, 0.0)))
    earth.velocity = units.ms(np.array((0.0, 0.0, 0.0)))
    earth.radius = units.km(6371)

    sat_one = stars[1]
    sat_one.mass = units.kg(1000)
    sat_one.radius = units.m(10)
    sat_one.position = units.km(np.array((6371 + 242, 0.0, 0.0)))
    sat_one.velocity = units.ms(np.array((0.0, 27359 / 3.6, 0.0)))

    sat_two = stars[2]
    sat_two.mass = units.kg(1000)
    sat_two.radius = units.m(10)
Ejemplo n.º 15
0
            self.instance.update_particles(stars)
            stars.savepoint()

        #self.instance.cleanup_module()
        #del instance we do that somewhere else...

    def cleanup(self):
        del self.instance


if __name__ == '__main__':

    I = SolarSystemModel()

    #make bodies in mem
    I.stars = datamodel.Stars(10)

    bodies = [
        I.Sun, I.Mercury, I.Venus, I.Earth, I.Moon, I.Mars, I.Jupiter,
        I.Saturn, I.Uranus, I.Neptune
    ]

    #set IC for bodies in mem according to data set and date
    for i, body in enumerate(bodies):

        I.stars[i].mass = body.mass
        I.stars[i].radius = body.radius
        r, v = body.get_vectors_at_date(date(1971, 10, 26))
        I.stars[i].position = units.AU(array((r[0], r[1], r[2])))
        I.stars[i].velocity = units.AUd(array((v[0], v[1], v[2])))
Ejemplo n.º 16
0

if __name__ == '__main__':

    I = SolarSystemModel()

    planets_data = Horizons()

    #Notable events
    start_date = date(1971, 10, 26)
    voyagerI_launch_date = date(1977, 9, 7)
    stop_date = date(1989, 10, 26)

    I.model_t0 = start_date

    planets = datamodel.Stars(10)
    voyagerI = datamodel.Particle()

    #set I.C. using Horizons database
    set_IC_at_date([
        planets_data.Sun, planets_data.Mercury, planets_data.Venus,
        planets_data.Earth, planets_data.Moon, planets_data.Mars,
        planets_data.Jupiter, planets_data.Saturn, planets_data.Uranus,
        planets_data.Neptune
    ], planets, start_date)

    set_IC_at_date([planets_data.VoyagerI], voyagerI.as_set(),
                   voyagerI_launch_date)

    planets.synchronize_to(I.code.particles)
Ejemplo n.º 17
0
    def setup_solar_system(self):
        convert_nbody = nbody_system.nbody_to_si(1.0 | units.MSun, 149.5e6 | units.km)
        
        stars = datamodel.Stars(8)
        
        sun = stars[0]
        sun.mass = units.MSun(1.0)
        sun.position = units.AU(array((0.0,0.0,0.0)))
        sun.velocity = units.AUd(array((0.0,0.0,0.0)))
        sun.radius = units.RSun(1.0)

   
        mercury = stars[1]
        mercury.mass = units.kg( 3.302e23)
        mercury.radius = units.km(2440) 
        mercury.position = units.AU(array((-1.812507519383936E-01, -4.238556570722329E-01, -1.858336536398257E-02)))
        mercury.velocity = units.AUd(array((2.028905659997442E-02, -9.482619060967475E-03, -2.636707283074494E-03)))

        venus = stars[2]
        venus.mass = units.kg(48.685e23)
        venus.radius = units.km(6051.8) 

        venus.position = units.AU(array((7.174859394658725E-01, -9.118094489213757E-02, -4.286369239375957E-02)))
        venus.velocity = units.AUd(array((2.569149540621095E-03,  1.995467986481682E-02,  1.246915402703626E-04)))

        earth = stars[3]
        earth.mass = units.kg(5.9736e24)

        earth.radius = units.km(6371) 
        earth.position = units.AU(array((   4.152751345538410E-01,  8.988236789078493E-01, -4.821560120168533E-05)))
        earth.velocity = units.AUd(array((  -1.588315644843389E-02,  7.210443860976745E-03, -1.350251461569625E-07)))
      
        moon = stars[4]
        moon.mass = units.kg(7.35e22)
        moon.radius = units.km(1738) 
        moon.position = units.AU(array((   4.138191074397691E-01,  8.965602570292573E-01, -2.762446418149536E-04)))
        moon.velocity = units.AUd(array((  -1.541527312550390E-02,  6.894586206029982E-03,  1.223837010915995E-05))) 
        
        mars = stars[5]
        mars.mass = units.kg(6.4185e23)
        mars.radius = units.km(3389.9)
        mars.position = units.AU(array((  -5.350147323170708E-01, -1.400272441929516E+00, -1.637545552747233E-02)))
        mars.velocity = units.AUd(array((  1.360625065710822E-02, -3.765876077406818E-03, -4.130340644254660E-04))) 
        
        jupiter = stars[6]
        jupiter.mass = units.kg(1898.13e24)
        jupiter.radius = units.km(71492)
        jupiter.position = units.AU(array((   2.503092399973117E+00, -4.468134118102924E+00, -3.752173268244928E-02)))
        jupiter.velocity = units.AUd(array((   6.490840561446090E-03,  4.046895067472646E-03, -1.620422227298534E-04))) 

        saturn = stars[7]
        saturn.mass = units.kg(5.68319e26 )
        saturn.radius = units.km(58232)
        saturn.position = units.AU(array((   -9.023156820924056E+00,  2.468810475231705E+00,  3.161126539154331E-01)))
        saturn.velocity = units.AUd(array(( -1.769097295887704E-03, -5.393257979873611E-03,  1.639859191780030E-04  ))) 

        dist = earth.position - moon.position 
        print "distance vector"+str(dist)

        print "distance %s\n" %  (dot(dist,dist)**0.5).as_quantity_in(units.m)#(dist*dist).sum()**0.5 

        velo = moon.velocity-earth.velocity
        print "orb velocity %s\n" % (dot(velo,velo)**0.5).as_quantity_in(units.m/units.s)

        return stars