Esempio n. 1
0
 def test3(self):
     class Code(object):
         def __init__(self):
             # mass
             self.data = []
             self.get_mass_called = False
             self.set_mass_called = False
             
         def get_number_of_particles(self):
             return  0 if not self.data else len(self.data[0])
             
         def get_mass(self,index):
             self.get_mass_called = True
             data_to_return = [self.data[0][i] for i in index]
             return units.kg(data_to_return)
             
         def set_mass(self,index,mass):
             self.set_mass_called = True
             pass
             
         def new_particle(self, mass):
             mass = mass.value_in(units.kg)
             self.data = [mass]
             return [i for i in range(len(mass))]
             
     code = Code()
     storage = InCodeAttributeStorage(
         code,
         NewParticleMethod(code.new_particle,("mass",)),
         None,
         code.get_number_of_particles,
         [],
         [
             ParticleGetAttributesMethod(code.get_mass,("mass",)),
         ],
         name_of_the_index = "index"
     )
     
     storage.add_particles_to_store(
         [1,2,3,4],
         ["mass"],
         [
             units.kg([1,2,3,4]),
         ]
     )
     
     self.assertEquals(len(storage), 4)
     
     self.assertEquals(storage.get_defined_attribute_names(), ["mass",])
     
     indices = storage.get_indices_of([2,3])
     index,mass = storage.get_values_in_store(indices,["index_in_code","mass"])
     self.assertTrue(code.get_mass_called)
     print index, mass
     self.assertEquals(index[0], 1)
     self.assertEquals(mass[0],  2 | units.kg)
     self.assertEquals(index[1], 2)
     self.assertEquals(mass[1],  3 | units.kg)
Esempio n. 2
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()
Esempio n. 3
0
    def test2(self):
        #not completed 
        convert_nbody = nbody_system.nbody_to_si(1.0 | units.MSun, 149.5e6 | units.km)

        instance = FDPS(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, "fdps-earth-sun.svg")
            figure.savefig(output_file)    
        
        instance.cleanup_code()
        instance.stop()
Esempio n. 4
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
Esempio n. 5
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
Esempio n. 6
0
def generate_dust(dust):
    #assuming two AU sphere
    n_particles = len(dust)
    initial_pos = units.AU(20.0 * (np.random.random([n_particles, 3]) - 0.5))
    initial_pos[::, 2] *= 0.001
    dust.position = initial_pos
    dust.velocity = rotate(dust.position, 0, 0, 0.5 * 3.1415)
    #dust.velocity = np.zeros([n_particles, 3])|units.AUd
    dust.mass = 100.0 * units.kg(np.ones(n_particles))
    dust.radius = 3000 * units.km(np.ones(n_particles))
    remove_outershell(dust)
    remove_core_dust(dust)
    def test3(self):
        class Code(object):
            def __init__(self):
                # mass
                self.data = []
                self.get_mass_called = False
                self.set_mass_called = False

            def get_number_of_particles(self):
                return 0 if not self.data else len(self.data[0])

            def get_mass(self, index):
                self.get_mass_called = True
                data_to_return = [self.data[0][i] for i in index]
                return units.kg(data_to_return)

            def set_mass(self, index, mass):
                self.set_mass_called = True
                pass

            def new_particle(self, mass):
                mass = mass.value_in(units.kg)
                self.data = [mass]
                return [i for i in range(len(mass))]

        code = Code()
        storage = InCodeAttributeStorage(
            code,
            NewParticleMethod(code.new_particle, ("mass", )),
            None,
            code.get_number_of_particles, [], [
                ParticleGetAttributesMethod(code.get_mass, ("mass", )),
            ],
            name_of_the_index="index")

        storage.add_particles_to_store([1, 2, 3, 4], ["mass"], [
            units.kg([1, 2, 3, 4]),
        ])

        self.assertEquals(len(storage), 4)

        self.assertEquals(storage.get_defined_attribute_names(), [
            "mass",
        ])

        indices = storage.get_indices_of([2, 3])
        index, mass = storage.get_values_in_store(indices,
                                                  ["index_in_code", "mass"])
        self.assertTrue(code.get_mass_called)
        self.assertEquals(index[0], 1)
        self.assertEquals(mass[0], 2 | units.kg)
        self.assertEquals(index[1], 2)
        self.assertEquals(mass[1], 3 | units.kg)
Esempio 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()
Esempio n. 9
0
    def new_system_sun_and_earth(self):
        result = Particles(2)
        sun = result[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 = result[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)))
        return result
Esempio n. 10
0
    def new_system_sun_and_earth(self):
        result = Particles(2)
        sun = result[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 = result[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)))
        return result
Esempio n. 11
0
    def test1(self):
        convert_nbody = nbody_system.nbody_to_si(1.0 | units.MSun, 149.5e6 | units.km)

        instance = FDPS(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()
Esempio n. 12
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
Esempio n. 13
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(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)))
        
        return stars
Esempio n. 14
0
    def test16(self):
        convert_nbody = nbody_system.nbody_to_si(1.0 | units.MSun, 149.5e6 | units.km)
    
        smalln = SmallN(convert_nbody)
        smalln.initialize_code()
        smalln.dt_dia = 5000
        
        stars = self.new_system_of_sun_and_earth()
        
        moon = datamodel.Particle()
        moon.mass = units.kg(7.3477e22)
        moon.radius = units.km(1737.10) 
        moon.position = units.km(numpy.array((149.5e6 + 384.399 ,0.0,0.0)))
        moon.velocity = units.ms(numpy.array((0.0,29800 + 1022,0.0)))
        
        stars.add_particle(moon)
        
        earth = stars[1]
                
        smalln.particles.add_particles(stars)
        
        smalln.evolve_model(365.0 | units.day)
        smalln.update_particle_tree()
        smalln.update_particle_set()
        

        self.assertEquals(len(smalln.particles), 5)
        
        
        self.assertEarthAndMoonWasDetectedAsBinary(smalln.particles, stars)
        
        
        inmemory = smalln.particles.copy()
        self.assertEarthAndMoonWasDetectedAsBinary(inmemory, stars)
        
        test_results_path = self.get_path_to_results()
        output_file = os.path.join(test_results_path, "newsmalln-test16.hdf5")
        if os.path.exists(output_file):
            os.remove(output_file)
            
        io.write_set_to_file(smalln.particles, output_file, "hdf5")
        fromfile = io.read_set_from_file(output_file, "hdf5")
        self.assertEarthAndMoonWasDetectedAsBinary(fromfile, stars)
Esempio n. 15
0
    def test16(self):
        convert_nbody = nbody_system.nbody_to_si(1.0 | units.MSun,
                                                 149.5e6 | units.km)

        smalln = SmallN(convert_nbody)
        smalln.initialize_code()
        smalln.dt_dia = 5000

        stars = self.new_system_of_sun_and_earth()

        moon = datamodel.Particle()
        moon.mass = units.kg(7.3477e22)
        moon.radius = units.km(1737.10)
        moon.position = units.km(numpy.array((149.5e6 + 384.399, 0.0, 0.0)))
        moon.velocity = units.ms(numpy.array((0.0, 29800 + 1022, 0.0)))

        stars.add_particle(moon)

        earth = stars[1]

        smalln.particles.add_particles(stars)

        smalln.evolve_model(365.0 | units.day)
        smalln.update_particle_tree()
        smalln.update_particle_set()

        self.assertEqual(len(smalln.particles), 5)

        self.assertEarthAndMoonWasDetectedAsBinary(smalln.particles, stars)

        inmemory = smalln.particles.copy()
        self.assertEarthAndMoonWasDetectedAsBinary(inmemory, stars)

        test_results_path = self.get_path_to_results()
        output_file = os.path.join(test_results_path, "newsmalln-test16.hdf5")
        if os.path.exists(output_file):
            os.remove(output_file)

        io.write_set_to_file(smalln.particles, output_file, "hdf5")
        fromfile = io.read_set_from_file(output_file, "hdf5")
        self.assertEarthAndMoonWasDetectedAsBinary(fromfile, stars)
        smalln.stop()
Esempio n. 16
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
Esempio n. 17
0
    P = planetarium.SolarSystemView((640, 400))

    for t in range(start_date.toordinal(), voyagerI_launch_date.toordinal(),
                   1):
        I.evolve(t, t + 1, 1)
        P.renderamuse(I.stars)
        P.handle_events()
        if not P.go:
            P.go = True
            break

    voyagers = datamodel.Stars(1)
    voyagerI = voyagers[0]
    VoyagerI = LoadStar('voyagerI')
    voyagerI.mass = units.kg(500)
    voyagerI.radius = units.m(20)
    r, v = VoyagerI.get_vectors_at_date(voyagerI_launch_date)
    voyagerI.position = units.AU(array((r[0], r[1], r[2])))
    voyagerI.velocity = units.AUd(array((v[0], v[1], v[2])))
    I.stars.add_particles(voyagers)
    I.stars.synchronize_to(I.instance.particles)
    I.instance.timestep = 0.002
    #I.instance.setup_module()
    #I.instance.setup_particles(I.stars)

    two_body_mode = False

    for t in arange(voyagerI_launch_date.toordinal(),
                    date(1987, 9, 7).toordinal(), 0.2):
        I.evolve(t, t + 1, 0.2)  #till voyager launch + some days
Esempio n. 18
0
 def get_mass(self,index):
     self.get_mass_called = True
     data_to_return = [self.data[3][i] for i in index]
     return units.kg(data_to_return)
Esempio n. 19
0
    def test4(self):
        class Code(object):
            def __init__(self):
                # mass
                self.data = []
                self.get_mass_called = False
                self.set_mass_called = False
                self.number_of_particles = 0

            def get_number_of_particles(self):
                return self.number_of_particles

            def get_mass(self, index):
                self.get_mass_called = True
                data_to_return = [self.data[i] for i in index]
                return units.kg(data_to_return)

            def set_mass(self, index, mass):
                self.set_mass_called = True
                pass

            def new_particle(self, mass):
                mass = mass.value_in(units.kg)
                self.data = mass
                self.number_of_particles = len(self.data)
                return [i for i in range(len(mass))]

        code = Code()
        storage = InCodeAttributeStorage(
            code,
            NewParticleMethod(code.new_particle, ("mass", )),
            None,
            code.get_number_of_particles, [], [
                ParticleGetAttributesMethod(code.get_mass, ("mass", )),
            ],
            name_of_the_index="index")

        storage.add_particles_to_store(
            numpy.asarray([1, 2, 3, 4], dtype='uint64'), ["mass"], [
                units.kg([1, 2, 3, 4]),
            ])

        self.assertEquals(len(storage), 4)

        storage._remove_indices([
            1,
            2,
        ])
        code.number_of_particles = 2
        indices = storage.get_indices_of([1, 4])
        index, mass = storage.get_values_in_store(indices,
                                                  ["index_in_code", "mass"])

        self.assertEquals(index[0], 0)
        self.assertEquals(index[1], 3)
        self.assertEquals(mass[0], 1 | units.kg)
        self.assertEquals(mass[1], 4 | units.kg)

        self.assertEquals(len(storage), 2)

        storage._add_indices([4, 5])
        code.data = numpy.concatenate((code.data, [5, 6]))

        code.number_of_particles = 4
        self.assertEquals(len(storage), 4)

        indices = storage.get_indices_of(storage.particle_keys)
        mass, = storage.get_values_in_store(indices, ["mass"])

        self.assertEquals(mass[0], 1 | units.kg)
        self.assertEquals(mass[1], 4 | units.kg)
        self.assertEquals(mass[2], 5 | units.kg)
        self.assertEquals(mass[3], 6 | units.kg)

        storage._remove_indices([
            4,
        ])
        code.number_of_particles = 3
        self.assertEquals(len(storage), 3)

        indices = storage.get_indices_of(storage.particle_keys)
        mass, = storage.get_values_in_store(indices, ["mass"])

        self.assertEquals(mass[0], 1 | units.kg)
        self.assertEquals(mass[1], 4 | units.kg)
        self.assertEquals(mass[2], 6 | units.kg)
Esempio n. 20
0
 def get_mass(self,index):
     data_to_return = [self.data[i][0] for i in index]
     return units.kg(data_to_return)
Esempio n. 21
0
 def test2(self):
     class Code(object):
         def __init__(self):
             # x,y,z,mass
             self.data = []
             self.get_position_called = False
             self.set_position_called = False
             self.get_mass_called = False
             self.set_mass_called = False
             
         def get_number_of_particles(self):
             return  0 if not self.data else len(self.data[0])
             
         def get_position(self,index):
             self.get_position_called = True
             data_to_return = [(self.data[0][i], self.data[1][i], self.data[2][i]) for i in index]
             data_to_return = numpy.asarray(data_to_return).reshape(3,-1)
             return [units.m(x) for x in data_to_return]
         
         def get_mass(self,index):
             self.get_mass_called = True
             data_to_return = [self.data[3][i] for i in index]
             return units.kg(data_to_return)
             
         def set_position(self,index,x,y,z):
             self.set_position_called = True
             pass
             
         def set_mass(self,index,mass):
             self.set_mass_called = True
             pass
             
         def new_particle(self, x, y, z, mass):
             x = x.value_in(units.m)
             y = y.value_in(units.m)
             z = z.value_in(units.m)
             mass = mass.value_in(units.kg)
             self.data = [x,y,z, mass]
             return [i for i in range(len(x))]
             
     code = Code()
     storage = InCodeAttributeStorage(
         code,
         NewParticleMethod(code.new_particle,("x","y","z","mass")),
         None,
         code.get_number_of_particles,
         [],
         [
             ParticleGetAttributesMethod(code.get_position,("x","y","z")),
             ParticleGetAttributesMethod(code.get_mass,("mass",)),
         ],
         name_of_the_index = "index"
     )
     
     storage.add_particles_to_store(
         [1,2,3,4],
         ["x","y","z", "mass"],
         [
             units.m([1,2,3,4]),
             units.m([2,3,4,5]),
             units.m([3,4,5,6]),
             units.kg([13,14,15,16]),
         ]
     )
     
     self.assertEquals(len(storage), 4)
     
     self.assertEquals(storage.get_defined_attribute_names(), [ "mass", "x","y","z"])
     
     self.assertFalse(code.get_position_called)
     self.assertFalse(code.get_mass_called)
     indices = storage.get_indices_of([2,3])
     x,y,mass = storage.get_values_in_store(indices,["x","y","mass"])
     self.assertTrue(code.get_position_called)
     self.assertTrue(code.get_mass_called)
     self.assertEquals(x[1], 3 | units.m)
     self.assertEquals(mass[1], 15 | units.kg)
Esempio n. 22
0
 def test4(self):
     class Code(object):
         def __init__(self):
             # mass
             self.data = []
             self.get_mass_called = False
             self.set_mass_called = False
             self.number_of_particles = 0
             
         def get_number_of_particles(self):
             return  self.number_of_particles
             
         def get_mass(self,index):
             self.get_mass_called = True
             data_to_return = [self.data[i] for i in index]
             return units.kg(data_to_return)
             
         def set_mass(self,index,mass):
             self.set_mass_called = True
             pass
             
         def new_particle(self, mass):
             mass = mass.value_in(units.kg)
             self.data = mass
             self.number_of_particles = len(self.data)
             return [i for i in range(len(mass))]
             
     code = Code()
     storage = InCodeAttributeStorage(
         code,
         NewParticleMethod(code.new_particle,("mass",)),
         None,
         code.get_number_of_particles,
         [],
         [
             ParticleGetAttributesMethod(code.get_mass,("mass",)),
         ],
         name_of_the_index = "index"
     )
     
     storage.add_particles_to_store(
         numpy.asarray([1,2,3,4], dtype='uint64'),
         ["mass"],
         [
             units.kg([1,2,3,4]),
         ]
     )
     
     self.assertEquals(len(storage), 4)
     
     storage._remove_indices([1,2,])
     code.number_of_particles = 2
     indices = storage.get_indices_of([1,4])
     index,mass = storage.get_values_in_store(indices,["index_in_code","mass"])
     
     self.assertEquals(index[0], 0)
     self.assertEquals(index[1], 3)
     self.assertEquals(mass[0],  1 | units.kg)
     self.assertEquals(mass[1],  4 | units.kg)
     
     
     self.assertEquals(len(storage), 2)
     
     storage._add_indices([4,5])
     code.data = numpy.concatenate((code.data, [5, 6]))
     
     code.number_of_particles = 4
     self.assertEquals(len(storage), 4)
     
     indices = storage.get_indices_of(storage.particle_keys)
     mass, = storage.get_values_in_store(indices,["mass"])
     
     self.assertEquals(mass[0],  1 | units.kg)
     self.assertEquals(mass[1],  4 | units.kg)
     self.assertEquals(mass[2],  5 | units.kg)
     self.assertEquals(mass[3],  6 | units.kg)
     
     storage._remove_indices([4,])
     code.number_of_particles = 3
     self.assertEquals(len(storage), 3)
     
     indices = storage.get_indices_of(storage.particle_keys)
     mass, = storage.get_values_in_store(indices,["mass"])
     
     self.assertEquals(mass[0],  1 | units.kg)
     self.assertEquals(mass[1],  4 | units.kg)
     self.assertEquals(mass[2],  6 | units.kg)
Esempio n. 23
0
 def test5(self):
     class Code(object):
         def __init__(self):
             self.data = []
             self.number_of_particles = 0
             
         def get_number_of_particles(self):
             return  self.number_of_particles
             
         def get_mass(self,index):
             data_to_return = [self.data[i][0] for i in index]
             return units.kg(data_to_return)
         
         def get_children(self,index):
             return [(self.data[i][1]) for i in index], [(self.data[i][2]) for i in index]
         
         def new_particle(self, mass):
             mass = mass.value_in(units.kg)
             self.data = [[x,-1,-1] for x in mass]
             self.number_of_particles = len(self.data)
             return [i for i in range(len(mass))]
         
     code = Code()
 
     children_getter = ParticleGetAttributesMethod(
                 code.get_children,
                 ('child1', 'child2',)
     )
     children_getter.index_output_attributes = set(['child1','child2'])
  
     storage = InCodeAttributeStorage(
         code,
         NewParticleMethod(code.new_particle,("mass",)),
         None,
         code.get_number_of_particles,
         [],
         [
             ParticleGetAttributesMethod(code.get_mass,("mass",)),
             children_getter
         ],
         name_of_the_index = "index"
     )
     
     storage.add_particles_to_store(
         numpy.asarray([100,200,300,400], dtype='uint64'),
         ["mass"],
         [
             units.kg([1,2,3,4]),
         ]
     )
     
     self.assertEquals(len(storage), 4)
 
     indices = storage.get_indices_of([100,400])
     mass = storage.get_values_in_store(indices,["mass",])[0]
     print mass
     self.assertEquals(mass[0], 1.0 | units.kg)
     self.assertEquals(mass[1], 4.0 | units.kg)
 
     code.data[0][1] = 1
     code.data[0][2] = 2
 
     indices = storage.get_indices_of([100])
     child1,child2 = storage.get_values_in_store(indices,['child1', 'child2'])
     print child1
 
     self.assertEquals(child1[0].number, 200)
     self.assertEquals(child2[0].number, 300)
Esempio n. 24
0
        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])))

    I.instance.setup_particles(I.stars)

    I.model_t0 = date(1971, 10, 26)
    I.evolve(date(1971, 10, 26), date(1978, 1, 3),
             10)  #till voyager launch + some days

    voyagers = datamodel.Stars(1)

    voyagerI = voyagers[0]  #I.stars.new_particle()
    #voyagerII = voyagers[1]# I.stars.new_particle()

    VoyagerI = LoadStar('voyagerI')
    voyagerI.mass = units.kg(1000)
    voyagerI.radius = units.m(20)
    r, v = VoyagerI.get_vectors_at_date(date(1978, 1, 3))

    Jx = I.stars[6].position.x.value_in(units.m)
    Jy = I.stars[6].position.y.value_in(units.m)
    Jz = I.stars[6].position.z.value_in(units.m)
    Jvx = I.stars[6].velocity.x.value_in(units.m / units.s)
    Jvy = I.stars[6].velocity.y.value_in(units.m / units.s)
    Jvz = I.stars[6].velocity.z.value_in(units.m / units.s)

    s = raw_input()
    voyagerI.position = units.AU(array((r[0], r[1], r[2])))
    voyagerI.velocity = units.AUd(array((v[0], v[1], v[2])))
    """
    VoyagerII = LoadStar('voyagerII')    
Esempio n. 25
0
    def __init__(self):

        self.Sun = LoadStar('sun')
        self.Sun.mass = units.MSun(1.0)
        self.Sun.radius = units.RSun(1.0)

        self.Mercury = LoadStar('mercury')
        self.Mercury.mass = units.kg(3.302e23)
        self.Mercury.radius = units.km(2440)

        self.Venus = LoadStar('venus')
        self.Venus.mass = units.kg(48.685e23)
        self.Venus.radius = units.km(6051.8)

        self.Earth = LoadStar('earth')
        self.Earth.mass = units.kg(5.9736e24)
        self.Earth.radius = units.km(6371)

        self.Moon = LoadStar('moon')
        self.Moon.mass = units.kg(7.35e22)
        self.Moon.radius = units.km(1738)

        self.Mars = LoadStar('mars')
        self.Mars.mass = units.kg(6.4185e23)
        self.Mars.radius = units.km(3389.9)

        self.Jupiter = LoadStar('jupiter')
        self.Jupiter.mass = units.kg(1898.13e24)
        self.Jupiter.radius = units.km(71492)
        #self.Jupiter.radius = units.km(0.000001)

        self.Saturn = LoadStar('saturn')
        self.Saturn.mass = units.kg(5.68319e26)
        self.Saturn.radius = units.km(58232)

        self.Uranus = LoadStar('uranus')
        self.Uranus.mass = units.kg(86.8103e24)
        self.Uranus.radius = units.km(26000)

        self.Neptune = LoadStar('neptune')
        self.Neptune.mass = units.kg(102.41e24)
        self.Neptune.radius = units.km(25000)

        self.VoyagerI = LoadStar('voyagerI')
        self.VoyagerI.mass = units.kg(500)
        self.VoyagerI.radius = units.m(20)

        self.VoyagerII = LoadStar('voyagerII')
        self.VoyagerII.mass = units.kg(1000)
        self.VoyagerII.radius = units.m(20)
Esempio n. 26
0
 def get_mass(self, index):
     self.get_mass_called = True
     data_to_return = [self.data[3][i] for i in index]
     return units.kg(data_to_return)
Esempio n. 27
0
    def test5(self):
        class Code(object):
            def __init__(self):
                self.data = []
                self.number_of_particles = 0

            def get_number_of_particles(self):
                return self.number_of_particles

            def get_mass(self, index):
                data_to_return = [self.data[i][0] for i in index]
                return units.kg(data_to_return)

            def get_children(self, index):
                return [(self.data[i][1]) for i in index], [(self.data[i][2])
                                                            for i in index]

            def new_particle(self, mass):
                mass = mass.value_in(units.kg)
                self.data = [[x, -1, -1] for x in mass]
                self.number_of_particles = len(self.data)
                return [i for i in range(len(mass))]

        code = Code()

        children_getter = ParticleGetAttributesMethod(code.get_children, (
            'child1',
            'child2',
        ))
        children_getter.index_output_attributes = set(['child1', 'child2'])

        storage = InCodeAttributeStorage(
            code,
            NewParticleMethod(code.new_particle, ("mass", )),
            None,
            code.get_number_of_particles, [], [
                ParticleGetAttributesMethod(code.get_mass,
                                            ("mass", )), children_getter
            ],
            name_of_the_index="index")

        storage.add_particles_to_store(
            numpy.asarray([100, 200, 300, 400], dtype='uint64'), ["mass"], [
                units.kg([1, 2, 3, 4]),
            ])

        self.assertEquals(len(storage), 4)

        indices = storage.get_indices_of([100, 400])
        mass = storage.get_values_in_store(indices, [
            "mass",
        ])[0]
        self.assertEquals(mass[0], 1.0 | units.kg)
        self.assertEquals(mass[1], 4.0 | units.kg)

        code.data[0][1] = 1
        code.data[0][2] = 2

        indices = storage.get_indices_of([100])
        child1, child2 = storage.get_values_in_store(indices,
                                                     ['child1', 'child2'])

        self.assertEquals(child1[0].number, 200)
        self.assertEquals(child2[0].number, 300)
Esempio n. 28
0
 def get_mass(self, index):
     data_to_return = [self.data[i][0] for i in index]
     return units.kg(data_to_return)
Esempio n. 29
0
    def test2(self):
        class Code(object):
            def __init__(self):
                # x,y,z,mass
                self.data = []
                self.get_position_called = False
                self.set_position_called = False
                self.get_mass_called = False
                self.set_mass_called = False

            def get_number_of_particles(self):
                return 0 if not self.data else len(self.data[0])

            def get_position(self, index):
                self.get_position_called = True
                data_to_return = [(self.data[0][i], self.data[1][i],
                                   self.data[2][i]) for i in index]
                data_to_return = numpy.asarray(data_to_return).reshape(3, -1)
                return [units.m(x) for x in data_to_return]

            def get_mass(self, index):
                self.get_mass_called = True
                data_to_return = [self.data[3][i] for i in index]
                return units.kg(data_to_return)

            def set_position(self, index, x, y, z):
                self.set_position_called = True
                pass

            def set_mass(self, index, mass):
                self.set_mass_called = True
                pass

            def new_particle(self, x, y, z, mass):
                x = x.value_in(units.m)
                y = y.value_in(units.m)
                z = z.value_in(units.m)
                mass = mass.value_in(units.kg)
                self.data = [x, y, z, mass]
                return [i for i in range(len(x))]

        code = Code()
        storage = InCodeAttributeStorage(
            code,
            NewParticleMethod(code.new_particle, ("x", "y", "z", "mass")),
            None,
            code.get_number_of_particles, [], [
                ParticleGetAttributesMethod(code.get_position,
                                            ("x", "y", "z")),
                ParticleGetAttributesMethod(code.get_mass, ("mass", )),
            ],
            name_of_the_index="index")

        storage.add_particles_to_store([1, 2, 3, 4], ["x", "y", "z", "mass"], [
            units.m([1, 2, 3, 4]),
            units.m([2, 3, 4, 5]),
            units.m([3, 4, 5, 6]),
            units.kg([13, 14, 15, 16]),
        ])

        self.assertEquals(len(storage), 4)

        self.assertEquals(storage.get_defined_attribute_names(),
                          ["mass", "x", "y", "z"])

        self.assertFalse(code.get_position_called)
        self.assertFalse(code.get_mass_called)
        indices = storage.get_indices_of([2, 3])
        x, y, mass = storage.get_values_in_store(indices, ["x", "y", "mass"])
        self.assertTrue(code.get_position_called)
        self.assertTrue(code.get_mass_called)
        self.assertEquals(x[1], 3 | units.m)
        self.assertEquals(mass[1], 15 | units.kg)
Esempio n. 30
0
        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)
    sat_two.position = units.km(np.array((6371 + 242, 100.0, 0.0)))
    sat_two.velocity = units.ms(np.array((0.0, 27359 / 3.6, 0.0)))