Exemple #1
0
 def test1(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()
     earth = stars[1]
             
     smalln.particles.add_particles(stars)
     
     smalln.evolve_model(365.0 | units.day)
     smalln.particles.copy_values_of_all_attributes_to(stars)
     
     position_at_start = earth.position.value_in(units.AU)[0]
     position_after_full_rotation = earth.position.value_in(units.AU)[0]
     self.assertAlmostEqual(position_at_start, position_after_full_rotation, 6)
     
     smalln.evolve_model(365.0 + (365.0 / 2) | units.day)
     
     smalln.particles.copy_values_of_all_attributes_to(stars)
     position_after_half_a_rotation = earth.position.value_in(units.AU)[0]
     self.assertAlmostEqual(-position_at_start, position_after_half_a_rotation, 2)
             
     smalln.evolve_model(365.0 + (365.0 / 2) + (365.0 / 4)  | units.day)
     
     smalln.particles.copy_values_of_all_attributes_to(stars)
     position_after_half_a_rotation = earth.position.value_in(units.AU)[1]
     self.assertAlmostEqual(-position_at_start, position_after_half_a_rotation, 3)
     
     smalln.cleanup_code()
     
     smalln.stop()
Exemple #2
0
    def test3(self):
        convert_nbody = nbody_system.nbody_to_si(1.0 | units.MSun, 149.5e6 | units.km)

        instance = SmallN(convert_nbody)
        instance.initialize_code()
        instance.dt_dia = 5000
        
        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()
        
        instance.stop()
Exemple #3
0
    def test3(self):
        convert_nbody = nbody_system.nbody_to_si(1.0 | units.MSun,
                                                 149.5e6 | units.km)

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

        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()

        instance.stop()
Exemple #4
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)
Exemple #5
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()
Exemple #6
0
 def test2(self):
     convert_nbody = nbody_system.nbody_to_si(1.0 | units.MSun, 149.5e6 | units.km)
 
     instance = SmallN(convert_nbody)
     instance.initialize_code()
     instance.dt_dia = 5000
     
     stars = self.new_system_of_sun_and_earth()
     earth = stars[1]
     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()
     
     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, "smalln-earth-sun2.svg")
         figure.savefig(output_file)
     
     
     
     instance.cleanup_code()
     instance.stop()
Exemple #7
0
    def test2(self):
        convert_nbody = nbody_system.nbody_to_si(1.0 | units.MSun,
                                                 149.5e6 | units.km)

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

        stars = self.new_system_of_sun_and_earth()
        earth = stars[1]
        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()

        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 = [t_x[1].value_in(units.AU) for t_x in x_points]
            y_points_in_AU = [t_x1[1].value_in(units.AU) for t_x1 in 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,
                                       "smalln-earth-sun2.svg")
            figure.savefig(output_file)

        instance.cleanup_code()
        instance.stop()
Exemple #8
0
    def test1(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()
        earth = stars[1]

        smalln.particles.add_particles(stars)

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

        position_at_start = earth.position.value_in(units.AU)[0]
        position_after_full_rotation = earth.position.value_in(units.AU)[0]
        self.assertAlmostEqual(position_at_start, position_after_full_rotation,
                               6)

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

        smalln.particles.copy_values_of_all_attributes_to(stars)
        position_after_half_a_rotation = earth.position.value_in(units.AU)[0]
        self.assertAlmostEqual(-position_at_start,
                               position_after_half_a_rotation, 2)

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

        smalln.particles.copy_values_of_all_attributes_to(stars)
        position_after_half_a_rotation = earth.position.value_in(units.AU)[1]
        self.assertAlmostEqual(-position_at_start,
                               position_after_half_a_rotation, 3)

        smalln.cleanup_code()

        smalln.stop()