Beispiel #1
0
    def test3(self):
        convert_nbody=nbody_system.nbody_to_si(1.0|units.MSun, 1.0|units.yr/(2.0*pi))
        instance = Mikkola(convert_nbody)
        instance.parameters.lightspeed = constants.c
        stars = self.new_system_of_Hulse_Taylor_pulsar()
        instance.particles.add_particles(stars)
        Hulse = stars[0]
        Taylor = stars[1]
        
        postion_at_start = Taylor.position.value_in(units.AU)[0]
        
        #orbital period
        #see http://www.johnstonsarchive.net/relativity/binpulsar.html
        period_HTpulsar = 7.75 | units.hour
        #period_HTpulsar = 77.51939106 | units.hour
        # period for abseidal motion
        #        period_HTpulsar = 85.0 | units.yr #4.2degrees/year
        #period_HTpulsar = 1.0 | units.yr 
        instance.evolve_model(period_HTpulsar)
        channel = instance.particles.new_channel_to(stars)
        channel.copy()

        postion_after_full_rotation = Taylor.position.value_in(units.AU)[0]
       
        print "Time=", instance.model_time, period_HTpulsar
        self.assertAlmostEqual(postion_at_start, postion_after_full_rotation, 3)
        
        instance.stop()
        del instance
Beispiel #2
0
def get_mikkola(converter):
    instance = Mikkola(converter)
    instance.initialize_code()
    instance.parameters.set_defaults()
    instance.parameters.lightspeed = constants.c
    #instance.parameters.timestep = 0.01 | nbody_system.time
    #print >> sys.stderr, 'c/v=', instance.parameters.lightspeed

    return instance
Beispiel #3
0
    def test14(self):
        
        convert_nbody=nbody_system.nbody_to_si(1.0|units.MSun, 1.0|units.yr/(2.0*pi))
        stars = datamodel.Stars(3)
        stars[0].mass = 1.0 | units.MSun
        stars[0].radius = 1.0| units.RSun
        stars[0].position = [0.0, 0, 0] | units.km
        stars[0].velocity = [0.0,0.0,0.0] | units.km/units.s

        stars[1].mass = 1.0 | units.MSun
        stars[1].radius = 1.0| units.RSun
        stars[1].position = [0.1, 0, 0] | units.RSun
        stars[1].velocity = [-0.4, 0.0, 0.0] | units.km/units.s
        
        
        stars[2].mass = 1e-9 | units.MSun
        stars[2].radius = 1.0| units.RSun
        stars[2].position = [10000, 0, 0] | units.RSun
        stars[2].velocity = [0.0, -100, 0.0] | units.km/units.s
        
        
        instance = Mikkola(convert_nbody)
        instance.particles.add_particles(stars)
        instance.evolve_model(0.3 | units.yr)
        
        pos11 = quantities.as_vector_quantity(instance.get_position(1))
        pos12 = quantities.as_vector_quantity(instance.get_position(2))
        instance.stop()
        
        convert_nbody=nbody_system.nbody_to_si(1.0|units.MSun, 1.0|units.yr/(2.0*pi))
        
        instance = Mikkola(convert_nbody)
        stars = datamodel.Stars(2)
        stars[0].mass = 1.0 | units.MSun
        stars[0].radius = 1.0| units.RSun
        stars[0].position = [0.0, 0, 0] | units.km
        stars[0].velocity = [0.0,0.0,0.0] | units.km/units.s

        stars[1].mass = 1.0 | units.MSun
        stars[1].radius = 1.0| units.RSun
        stars[1].position = [0.1, 0, 0] | units.RSun
        stars[1].velocity = [-0.4, 0.0, 0.0] | units.km/units.s
        
        
        instance.particles.add_particles(stars)
        self.assertRaises(exceptions.AmuseException, instance.evolve_model, 0.3 | units.yr)  
        pos21 = quantities.as_vector_quantity(instance.get_position(1))
        pos22 = quantities.as_vector_quantity(instance.get_position(2))
        instance.stop()
        
        # positions will not be the same but distances will be comparable
        self.assertAlmostRelativeEquals((pos22-pos21).length(), (pos12-pos11).length(), 1)
Beispiel #4
0
    def test7(self):
        convert_nbody = nbody_system.nbody_to_si(1.0 | units.MSun,
                                                 1.0 | units.yr / (2.0 * pi))

        instance = Mikkola(convert_nbody)

        stars = datamodel.Stars(3)
        stars[0].mass = 1.0 | units.MSun
        stars[0].radius = 1.0 | units.RSun
        stars[0].position = [0.0, 0, 0] | units.km
        stars[0].velocity = [0.0, 0.0, 0.0] | units.km / units.s

        stars[1].mass = 1.0 | units.MSun
        stars[1].radius = 1.0 | units.RSun
        stars[1].position = [0.1, 0, 0] | units.RSun
        stars[1].velocity = [-0.4, 0.0, 0.0] | units.km / units.s

        stars[2].mass = 0.01 | units.MSun
        stars[2].radius = 1.0 | units.RSun
        stars[2].position = [6000, 0, 0] | units.RSun
        stars[2].velocity = [0.0, -10, 0.0] | units.km / units.s

        instance.particles.add_particles(stars)

        instance.evolve_model(0.25 | units.yr)

        self.assertEqual(instance.get_number_of_particles_added(), 1)
        self.assertEqual(instance.get_id_of_added_particle(0), 4)
        child1, child2 = instance.get_children_of_particle([4])
        self.assertEqual(child1[0], instance.particles[0])
        self.assertEqual(child2[0], instance.particles[1])
        for i in range(3):
            child1, child2 = instance.get_children_of_particle([i + 1])
            self.assertEqual(child1[0], None)
            self.assertEqual(child2[0], None)
Beispiel #5
0
    def test13(self):
        convert_nbody = nbody_system.nbody_to_si(1.0 | units.MSun,
                                                 1.0 | units.yr / (2.0 * pi))

        instance = Mikkola(convert_nbody)
        stars = datamodel.Stars(2)
        stars[0].mass = 1.0 | units.MSun
        stars[0].radius = 1.0 | units.RSun
        stars[0].position = [0.0, 0, 0] | units.km
        stars[0].velocity = [0.0, 0.0, 0.0] | units.km / units.s

        stars[1].mass = 1.0 | units.MSun
        stars[1].radius = 1.0 | units.RSun
        stars[1].position = [0.1, 0, 0] | units.RSun
        stars[1].velocity = [-0.4, 0.0, 0.0] | units.km / units.s

        instance.particles.add_particles(stars)
        self.assertRaises(exceptions.AmuseException, instance.evolve_model,
                          0.3 | units.yr)
        self.assertEqual(instance.get_number_of_particles_added(), 1)
        self.assertEqual(instance.get_id_of_added_particle(0), 3)
        instance.update_particle_set()
        child1, child2 = instance.get_children_of_particle([3])
        self.assertEqual(child1[0], instance.particles[0])
        self.assertEqual(child2[0], instance.particles[1])
        self.assertAlmostRelativeEquals(instance.get_mass(3), 2 | units.MSun)
Beispiel #6
0
 def test16(self):
     particles = datamodel.Particles(3)
     particles.mass = [0.1, 0.1, 0.0001] | nbody_system.mass
     particles.radius = [0.3, 0.3, 0.1] | nbody_system.length
     particles.x = [-0.5, 0.5, 10] | nbody_system.length
     particles.y = 0 | nbody_system.length
     particles.z = 0 | nbody_system.length
     particles.velocity = [0, 0, 0] | nbody_system.speed
     particles[-1].vy = 10 | nbody_system.speed
     instance = Mikkola()
     instance.initialize_code()
     instance.parameters.set_defaults()
     instance.parameters.lightspeed = 0 | nbody_system.speed
     instance.particles.add_particles(particles)
     collisions = instance.stopping_conditions.collision_detection
     collisions.enable()
     instance.evolve_model(10.0 | nbody_system.time)
     print(instance.particles.position)
     self.assertTrue(collisions.is_set())
     print(instance.model_time)
     print(len(collisions.particles(0)))
     self.assertTrue(instance.model_time < 2 | nbody_system.time)
     print(collisions.particles(0).key)
     print(collisions.particles(1).key)
     self.assertEqual(len(collisions.particles(0)), 1)
     self.assertEqual(len(collisions.particles(1)), 1)
     instance.stop()
Beispiel #7
0
    def test1(self):
        convert_nbody = nbody_system.nbody_to_si(1.0 | units.MSun,
                                                 1.0 | units.yr / (2.0 * pi))
        instance = Mikkola(convert_nbody)
        instance.parameters.timestep = 0.5 | units.day
        stars = self.new_system_of_sun_and_earth()
        instance.particles.add_particles(stars)
        Sun = stars[0]
        earth = stars[1]

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

        #        instance.evolve_model(365.0 | units.day)

        instance.evolve_model(1.0 | units.yr)
        channel = instance.particles.new_channel_to(stars)
        channel.copy()
        self.assertAlmostRelativeEquals(instance.potential_energy * -0.5,
                                        instance.kinetic_energy, 3)
        self.assertAlmostRelativeEquals(
            instance.radiated_gravitational_energy,
            -6222456075.98 | units.m**2 * units.kg * units.s**-2, 4)

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

        self.assertAlmostEqual(
            postion_at_start,
            instance.particles[1].position.value_in(units.AU)[0], 3)
        self.assertAlmostEqual(postion_at_start, postion_after_full_rotation,
                               3)

        instance.evolve_model(1.5 | units.yr)

        channel.copy()

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

        instance.evolve_model(1.75 | units.yr)

        channel.copy()

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

        self.assertAlmostEqual(-postion_at_start,
                               postion_after_half_a_rotation, 3)
        instance.cleanup_code()
        del instance
Beispiel #8
0
    def test11(self):
        instance = Mikkola()

        self.assertTrue(instance.parameters.evolve_to_exact_time)
        instance.parameters.evolve_to_exact_time = False
        self.assertFalse(instance.parameters.evolve_to_exact_time)

        self.assertEqual(instance.parameters.maximum_number_of_particles, 100)
        instance.parameters.maximum_number_of_particles = 200
        self.assertEqual(instance.parameters.maximum_number_of_particles, 200)

        self.assertAlmostRelativeEquals(instance.parameters.tolerance, 1e-13,
                                        6)
        instance.parameters.tolerance = 1e-10
        self.assertAlmostRelativeEquals(instance.parameters.tolerance, 1e-10)

        instance.stop()
Beispiel #9
0
 def test11(self):
     instance = Mikkola()
     
     self.assertTrue(instance.parameters.evolve_to_exact_time)
     instance.parameters.evolve_to_exact_time = False
     self.assertFalse(instance.parameters.evolve_to_exact_time)
     
     self.assertEquals(instance.parameters.maximum_number_of_particles, 100)
     instance.parameters.maximum_number_of_particles = 200
     self.assertEquals(instance.parameters.maximum_number_of_particles, 200)
     
     
     self.assertAlmostRelativeEquals(instance.parameters.tolerance, 1e-13, 6)
     instance.parameters.tolerance = 1e-10
     self.assertAlmostRelativeEquals(instance.parameters.tolerance, 1e-10)
     
     instance.stop()
Beispiel #10
0
    def test13(self):
        convert_nbody=nbody_system.nbody_to_si(1.0|units.MSun, 1.0|units.yr/(2.0*pi))
        
        instance = Mikkola(convert_nbody)
        stars = datamodel.Stars(2)
        stars[0].mass = 1.0 | units.MSun
        stars[0].radius = 1.0| units.RSun
        stars[0].position = [0.0, 0, 0] | units.km
        stars[0].velocity = [0.0,0.0,0.0] | units.km/units.s

        stars[1].mass = 1.0 | units.MSun
        stars[1].radius = 1.0| units.RSun
        stars[1].position = [0.1, 0, 0] | units.RSun
        stars[1].velocity = [-0.4, 0.0, 0.0] | units.km/units.s
        
        
        instance.particles.add_particles(stars)
        self.assertRaises(exceptions.AmuseException, instance.evolve_model, 0.3 | units.yr)  
        self.assertEquals(instance.get_number_of_particles_added(), 1) 
        self.assertEquals(instance.get_id_of_added_particle(0), 3)
        instance.update_particle_set()
        child1, child2 = instance.get_children_of_particle([3])
        self.assertEquals(child1[0], instance.particles[0])
        self.assertEquals(child2[0], instance.particles[1])
        self.assertAlmostRelativeEquals(instance.get_mass(3), 2 | units.MSun)
Beispiel #11
0
    def test15(self):
        convert_nbody=nbody_system.nbody_to_si(1.0|units.MSun, 1.0|units.yr/(2.0*pi))
        
        instance = Mikkola(convert_nbody)
        stars = datamodel.Stars(2)
        stars[0].mass = 1.0 | units.MSun
        stars[0].radius = 1.0| units.RSun
        stars[0].position = [0.0, 0, 0] | units.km
        stars[0].velocity = [0.0,0.0,0.0] | units.km/units.s

        stars[1].mass = 1.0 | units.MSun
        stars[1].radius = 1.0| units.RSun
        stars[1].position = [0.1, 0, 0] | units.RSun
        stars[1].velocity = [-0.4, 0.0, 0.0] | units.km/units.s
        
        
        instance.particles.add_particles(stars)
        try:
            instance.evolve_model(0.3 | units.yr)  
        except exceptions.AmuseException as ex:
            self.assertEquals(ex.errorcode, -4)
Beispiel #12
0
    def test15(self):
        convert_nbody = nbody_system.nbody_to_si(1.0 | units.MSun,
                                                 1.0 | units.yr / (2.0 * pi))

        instance = Mikkola(convert_nbody)
        stars = datamodel.Stars(2)
        stars[0].mass = 1.0 | units.MSun
        stars[0].radius = 1.0 | units.RSun
        stars[0].position = [0.0, 0, 0] | units.km
        stars[0].velocity = [0.0, 0.0, 0.0] | units.km / units.s

        stars[1].mass = 1.0 | units.MSun
        stars[1].radius = 1.0 | units.RSun
        stars[1].position = [0.1, 0, 0] | units.RSun
        stars[1].velocity = [-0.4, 0.0, 0.0] | units.km / units.s

        instance.particles.add_particles(stars)
        try:
            instance.evolve_model(0.3 | units.yr)
        except exceptions.AmuseException as ex:
            self.assertEqual(ex.errorcode, -4)
Beispiel #13
0
    def test3(self):
        convert_nbody = nbody_system.nbody_to_si(1.0 | units.MSun,
                                                 1.0 | units.yr / (2.0 * pi))
        instance = Mikkola(convert_nbody)
        instance.parameters.lightspeed = constants.c
        stars = self.new_system_of_Hulse_Taylor_pulsar()
        instance.particles.add_particles(stars)
        Hulse = stars[0]
        Taylor = stars[1]

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

        #orbital period
        #see http://www.johnstonsarchive.net/relativity/binpulsar.html
        period_HTpulsar = 7.75 | units.hour
        #period_HTpulsar = 77.51939106 | units.hour
        # period for abseidal motion
        #        period_HTpulsar = 85.0 | units.yr #4.2degrees/year
        #period_HTpulsar = 1.0 | units.yr
        instance.evolve_model(period_HTpulsar)
        channel = instance.particles.new_channel_to(stars)
        channel.copy()

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

        print("Time=", instance.model_time, period_HTpulsar)
        self.assertAlmostEqual(postion_at_start, postion_after_full_rotation,
                               3)

        instance.stop()
        del instance
Beispiel #14
0
    def test2(self):
        convert_nbody = nbody_system.nbody_to_si(1.0 | units.MSun,
                                                 1.0 | units.yr / (2.0 * pi))
        instance = Mikkola(convert_nbody)
        instance.parameters.timestep = 1 | units.day
        stars = self.new_system_of_sun_and_mercury()
        instance.particles.add_particles(stars)
        Sun = stars[0]
        mercury = stars[1]

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

        period_mercury = 87.9691 | units.day
        instance.evolve_model(period_mercury)
        channel = instance.particles.new_channel_to(stars)
        channel.copy()

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

        self.assertAlmostEqual(postion_at_start, postion_after_full_rotation,
                               4)

        instance.evolve_model(1.5 * period_mercury)

        channel.copy()

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

        instance.evolve_model(1.75 * period_mercury)

        channel.copy()

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

        self.assertAlmostEqual(-postion_at_start,
                               postion_after_half_a_rotation, 3)
        instance.cleanup_code()
        del instance
Beispiel #15
0
def HulseTaylor3():
    instance = Mikkola()
    stars = self.new_system_of_Hulse_Taylor_pulsar()
    instance.particles.add_particles(stars)
    Hulse = stars[0]
    Taylor = stars[1]
    
    postion_at_start = Taylor.position.value_in(units.AU)[0]
    
    #orbital period
    #period_HTpulsar = 7.751939106 | units.hour
    #period_HTpulsar = 77.51939106 | units.hour
    # period for abseidal motion
#        period_HTpulsar = 85.0 | units.yr #4.2degrees/year
    period_HTpulsar = 1.0 | units.yr 
    instance.evolve_model(period_HTpulsar)
    instance.particles.copy_values_of_state_attributes_to(stars)

    postion_after_full_rotation = Taylor.position.value_in(units.AU)[0]
   
    self.assertAlmostEqual(postion_at_start, postion_after_full_rotation, 4)
    
    instance.evolve_model(1.5 * period_HTpulsar)
    
    instance.particles.copy_values_of_state_attributes_to(stars)
    
    postion_after_half_a_rotation = Taylor.position.value_in(units.AU)[0]
    self.assertAlmostEqual(-postion_at_start, postion_after_half_a_rotation, 3)
    
    instance.evolve_model(1.75 * period_HTpulsar)
     
    instance.particles.copy_values_of_state_attributes_to(stars)
    
    postion_after_half_a_rotation = Taylor.position.value_in(units.AU)[1]
    
    self.assertAlmostEqual(-postion_at_start, postion_after_half_a_rotation, 3)
    instance.cleanup_code()
    del instance
Beispiel #16
0
    def test1(self):
        convert_nbody=nbody_system.nbody_to_si(1.0|units.MSun, 1.0|units.yr/(2.0*pi))
        instance = Mikkola(convert_nbody)
        instance.parameters.timestep = 0.5 | units.day
        stars = self.new_system_of_sun_and_earth()
        instance.particles.add_particles(stars)
        Sun = stars[0]
        earth = stars[1]
        
        postion_at_start = earth.position.value_in(units.AU)[0]
        
#        instance.evolve_model(365.0 | units.day)

        instance.evolve_model(1.0 | units.yr)
        channel = instance.particles.new_channel_to(stars)
        channel.copy()
        self.assertAlmostRelativeEquals(instance.potential_energy * -0.5, instance.kinetic_energy, 3)
        self.assertAlmostRelativeEquals(instance.radiated_gravitational_energy, -6222456075.98| units.m**2 * units.kg * units.s**-2, 4)
        
        postion_after_full_rotation = earth.position.value_in(units.AU)[0]
       
        self.assertAlmostEqual(postion_at_start, instance.particles[1].position.value_in(units.AU)[0], 3)
        self.assertAlmostEqual(postion_at_start, postion_after_full_rotation, 3)
        
        instance.evolve_model(1.5 | units.yr)
        
        channel.copy()
        
        postion_after_half_a_rotation = earth.position.value_in(units.AU)[0]
        self.assertAlmostEqual(-postion_at_start, postion_after_half_a_rotation, 3)
        
        instance.evolve_model(1.75  | units.yr)
         
        channel.copy()
        
        postion_after_half_a_rotation = earth.position.value_in(units.AU)[1]
        
        self.assertAlmostEqual(-postion_at_start, postion_after_half_a_rotation, 3)
        instance.cleanup_code()
        del instance
Beispiel #17
0
    def test6(self):
        convert_nbody = nbody_system.nbody_to_si(1.0 | units.MSun,
                                                 1.0 | units.yr / (2.0 * pi))

        instance = Mikkola(convert_nbody)

        stars = datamodel.Stars(4)
        stars[0].mass = 1.0 | units.MSun
        stars[0].radius = 1.0 | units.RSun
        stars[0].position = [0.0, 0, 0] | units.km
        stars[0].velocity = [0.0, 0.0, 0.0] | units.km / units.s

        stars[1].mass = 1.0 | units.MSun
        stars[1].radius = 1.0 | units.RSun
        stars[1].position = [0.1, 0, 0] | units.RSun
        stars[1].velocity = [-0.4, 0.0, 0.0] | units.km / units.s

        stars[2].mass = 1.0 | units.MSun
        stars[2].radius = 1.0 | units.RSun
        stars[2].position = [0.3, 0, 0] | units.RSun
        stars[2].velocity = [-0.4, 0.0, 0.0] | units.km / units.s

        stars[3].mass = 0.01 | units.MSun
        stars[3].radius = 1.0 | units.RSun
        stars[3].position = [6000, 0, 0] | units.RSun
        stars[3].velocity = [0.0, -10, 0.0] | units.km / units.s

        instance.particles.add_particles(stars)

        instance.evolve_model(0.25 | units.yr)

        self.assertEqual(instance.get_number_of_particles_added(), 2)
        self.assertRaises(Exception, instance.get_id_of_added_particle, [2])
        self.assertEqual(instance.get_id_of_added_particle(0), 5)
        self.assertEqual(instance.get_id_of_added_particle(1), 6)
        self.assertAlmostRelativeEquals(instance.get_mass(6), 3 | units.MSun)
        self.assertAlmostRelativeEquals(instance.get_mass(5), 2 | units.MSun)
        instance.update_particle_set()
        print(instance.particles[0].mass.as_quantity_in(units.MSun))
Beispiel #18
0
def HulseTaylor3():
    instance = Mikkola()
    stars = self.new_system_of_Hulse_Taylor_pulsar()
    instance.particles.add_particles(stars)
    Hulse = stars[0]
    Taylor = stars[1]
    
    postion_at_start = Taylor.position.value_in(units.AU)[0]
    
    #orbital period
    #period_HTpulsar = 7.751939106 | units.hour
    #period_HTpulsar = 77.51939106 | units.hour
    # period for abseidal motion
#        period_HTpulsar = 85.0 | units.yr #4.2degrees/year
    period_HTpulsar = 1.0 | units.yr 
    instance.evolve_model(period_HTpulsar)
    instance.particles.copy_values_of_state_attributes_to(stars)

    postion_after_full_rotation = Taylor.position.value_in(units.AU)[0]
   
    self.assertAlmostEqual(postion_at_start, postion_after_full_rotation, 4)
    
    instance.evolve_model(1.5 * period_HTpulsar)
    
    instance.particles.copy_values_of_state_attributes_to(stars)
    
    postion_after_half_a_rotation = Taylor.position.value_in(units.AU)[0]
    self.assertAlmostEqual(-postion_at_start, postion_after_half_a_rotation, 3)
    
    instance.evolve_model(1.75 * period_HTpulsar)
     
    instance.particles.copy_values_of_state_attributes_to(stars)
    
    postion_after_half_a_rotation = Taylor.position.value_in(units.AU)[1]
    
    self.assertAlmostEqual(-postion_at_start, postion_after_half_a_rotation, 3)
    instance.cleanup_code()
    del instance
Beispiel #19
0
 def test2(self):
     convert_nbody=nbody_system.nbody_to_si(1.0|units.MSun, 1.0|units.yr/(2.0*pi))
     instance = Mikkola(convert_nbody)
     instance.parameters.timestep = 1 | units.day
     stars = self.new_system_of_sun_and_mercury()
     instance.particles.add_particles(stars)
     Sun = stars[0]
     mercury = stars[1]
     
     postion_at_start = mercury.position.value_in(units.AU)[0]
     
     period_mercury = 87.9691 | units.day
     instance.evolve_model(period_mercury)
     channel = instance.particles.new_channel_to(stars)
     channel.copy()
     
     postion_after_full_rotation = mercury.position.value_in(units.AU)[0]
    
     self.assertAlmostEqual(postion_at_start, postion_after_full_rotation, 4)
     
     instance.evolve_model(1.5 * period_mercury)
     
     channel.copy()
     
     postion_after_half_a_rotation = mercury.position.value_in(units.AU)[0]
     self.assertAlmostEqual(-postion_at_start, postion_after_half_a_rotation, 3)
     
     instance.evolve_model(1.75 *period_mercury)
      
     channel.copy()
     
     postion_after_half_a_rotation = mercury.position.value_in(units.AU)[1]
     
     self.assertAlmostEqual(-postion_at_start, postion_after_half_a_rotation, 3)
     instance.cleanup_code()
     del instance
Beispiel #20
0
    def test6(self):
        convert_nbody=nbody_system.nbody_to_si(1.0|units.MSun, 1.0|units.yr/(2.0*pi))
        
        instance = Mikkola(convert_nbody)
        
        stars = datamodel.Stars(4)
        stars[0].mass = 1.0 | units.MSun
        stars[0].radius = 1.0| units.RSun
        stars[0].position = [0.0, 0, 0] | units.km
        stars[0].velocity = [0.0,0.0,0.0] | units.km/units.s

        stars[1].mass = 1.0 | units.MSun
        stars[1].radius = 1.0| units.RSun
        stars[1].position = [0.1, 0, 0] | units.RSun
        stars[1].velocity = [-0.4, 0.0, 0.0] | units.km/units.s
        
        stars[2].mass = 1.0 | units.MSun
        stars[2].radius = 1.0| units.RSun
        stars[2].position = [0.3, 0, 0] | units.RSun
        stars[2].velocity = [-0.4, 0.0, 0.0] | units.km/units.s
        
        stars[3].mass = 0.01 | units.MSun
        stars[3].radius = 1.0| units.RSun
        stars[3].position = [6000, 0, 0] | units.RSun
        stars[3].velocity = [0.0, -10, 0.0] | units.km/units.s
        
        
        instance.particles.add_particles(stars)
        
        instance.evolve_model(0.25 | units.yr)
        
        self.assertEquals(instance.get_number_of_particles_added(), 2)
        self.assertRaises(Exception, instance.get_id_of_added_particle, [2])
        self.assertEquals(instance.get_id_of_added_particle(0), 5)
        self.assertEquals(instance.get_id_of_added_particle(1), 6)
        self.assertAlmostRelativeEquals(instance.get_mass(6), 3 | units.MSun)
        self.assertAlmostRelativeEquals(instance.get_mass(5), 2 | units.MSun)
        instance.update_particle_set()
        print instance.particles[0].mass.as_quantity_in(units.MSun)
Beispiel #21
0
    def test10b(self):
        convert_nbody = nbody_system.nbody_to_si(1.0 | units.MSun,
                                                 1.0 | units.yr / (2.0 * pi))

        instance = Mikkola(convert_nbody)
        instance.parameters.maximum_number_of_particles = 3
        stars = datamodel.Stars(3)
        stars[0].mass = 1.0 | units.MSun
        stars[0].radius = 1.0 | units.RSun
        stars[0].position = [0.0, 0, 0] | units.km
        stars[0].velocity = [0.0, 0.0, 0.0] | units.km / units.s

        stars[1].mass = 1.0 | units.MSun
        stars[1].radius = 1.0 | units.RSun
        stars[1].position = [0.1, 0, 0] | units.RSun
        stars[1].velocity = [-0.4, 0.0, 0.0] | units.km / units.s

        stars[2].mass = 0.01 | units.MSun
        stars[2].radius = 1.0 | units.RSun
        stars[2].position = [6000, 0, 0] | units.RSun
        stars[2].velocity = [0.0, -10, 0.0] | units.km / units.s
        instance.particles.add_particles(stars)
        self.assertRaises(exceptions.AmuseException, instance.evolve_model,
                          0.3 | units.yr)
Beispiel #22
0
    def test7(self):
        convert_nbody=nbody_system.nbody_to_si(1.0|units.MSun, 1.0|units.yr/(2.0*pi))
        
        instance = Mikkola(convert_nbody)
        
        stars = datamodel.Stars(3)
        stars[0].mass = 1.0 | units.MSun
        stars[0].radius = 1.0| units.RSun
        stars[0].position = [0.0, 0, 0] | units.km
        stars[0].velocity = [0.0,0.0,0.0] | units.km/units.s

        stars[1].mass = 1.0 | units.MSun
        stars[1].radius = 1.0| units.RSun
        stars[1].position = [0.1, 0, 0] | units.RSun
        stars[1].velocity = [-0.4, 0.0, 0.0] | units.km/units.s
        
        
        stars[2].mass = 0.01 | units.MSun
        stars[2].radius = 1.0| units.RSun
        stars[2].position = [6000, 0, 0] | units.RSun
        stars[2].velocity = [0.0, -10, 0.0] | units.km/units.s
        
        
        instance.particles.add_particles(stars)
        
        instance.evolve_model(0.25 | units.yr)
        
        self.assertEquals(instance.get_number_of_particles_added(), 1)
        self.assertEquals(instance.get_id_of_added_particle(0), 4)
        child1, child2 = instance.get_children_of_particle([4])
        self.assertEquals(child1[0], instance.particles[0])
        self.assertEquals(child2[0], instance.particles[1])
        for i in range(3):
            child1, child2 = instance.get_children_of_particle([i+1])
            self.assertEquals(child1[0], None)
            self.assertEquals(child2[0], None)
Beispiel #23
0
    def test5(self):
        convert_nbody = nbody_system.nbody_to_si(1.0 | units.MSun,
                                                 1.0 | units.yr / (2.0 * pi))

        instance = Mikkola(convert_nbody)

        stars = datamodel.Stars(3)
        stars[0].mass = 1.0 | units.MSun
        stars[0].radius = 1.0 | units.RSun
        stars[0].position = [0.0, 0, 0] | units.km
        stars[0].velocity = [0.0, 0.0, 0.0] | units.km / units.s

        stars[1].mass = 1.0 | units.MSun
        stars[1].radius = 1.0 | units.RSun
        stars[1].position = [0.1, 0, 0] | units.RSun
        stars[1].velocity = [-0.4, 0.0, 0.0] | units.km / units.s

        stars[2].mass = 0.01 | units.MSun
        stars[2].radius = 1.0 | units.RSun
        stars[2].position = [6000, 0, 0] | units.RSun
        stars[2].velocity = [0.0, -10, 0.0] | units.km / units.s

        instance.particles.add_particles(stars)

        instance.evolve_model(0.25 | units.yr)

        self.assertEqual(instance.get_number_of_particles_added(), 1)
        self.assertRaises(Exception, instance.get_id_of_added_particle, [2])
        self.assertEqual(instance.get_id_of_added_particle(0), 4)
        self.assertAlmostRelativeEquals(instance.get_mass(4), 2 | units.MSun)
        self.assertAlmostRelativeEquals(instance.get_mass(1), 1 | units.MSun)
        self.assertAlmostRelativeEquals(instance.get_mass(2), 1 | units.MSun)
        pos1 = quantities.as_vector_quantity(instance.get_position(1))
        pos2 = quantities.as_vector_quantity(instance.get_position(2))
        posmerger = quantities.as_vector_quantity(instance.get_position(4))

        print(pos1)
        print(pos2)
        print(posmerger)
        distance = (pos1 - pos2).length()
        self.assertTrue(distance < 1e-4 | units.RSun)
        self.assertTrue(distance > 1e-6 | units.RSun)
        distance = (pos1 - posmerger).length()
        print(distance.as_quantity_in(units.RSun))
        self.assertAlmostRelativeEquals(distance, 0.718548184852 | units.RSun,
                                        5)
        distance = (pos2 - posmerger).length()
        print(distance.as_quantity_in(units.RSun))
        self.assertAlmostRelativeEquals(distance, 0.718548184852 | units.RSun,
                                        5)
        instance.update_particle_set()
        print(instance.particles[0].mass.as_quantity_in(units.MSun))
Beispiel #24
0
    def test8(self):
        convert_nbody=nbody_system.nbody_to_si(1.0|units.MSun, 1.0|units.yr/(2.0*pi))
        
        
        stars = datamodel.Stars(3)
        stars[0].mass = 1.0 | units.MSun
        stars[0].radius = 1.0| units.RSun
        stars[0].position = [0.0, 0, 0] | units.km
        stars[0].velocity = [0.0,0.0,0.0] | units.km/units.s

        stars[1].mass = 1.0 | units.MSun
        stars[1].radius = 1.0| units.RSun
        stars[1].position = [0.1, 0, 0] | units.RSun
        stars[1].velocity = [-0.4, 0.0, 0.0] | units.km/units.s
        
        
        stars[2].mass = 0.01 | units.MSun
        stars[2].radius = 1.0| units.RSun
        stars[2].position = [6000, 0, 0] | units.RSun
        stars[2].velocity = [0.0, -10, 0.0] | units.km/units.s
        
        
        instance1 = Mikkola(convert_nbody)
        instance1.particles.add_particles(stars)
        instance1.evolve_model(0.45 | units.yr)
        
        pos11 = quantities.as_vector_quantity(instance1.get_position(1))
        pos12 = quantities.as_vector_quantity(instance1.get_position(2))
        posmerger1 = quantities.as_vector_quantity(instance1.get_position(4))
        instance1.stop()
        
        instance2 = Mikkola(convert_nbody)
        instance2.particles.add_particles(stars)
        instance2.evolve_model(0.15 | units.yr)
        self.assertAlmostRelativeEquals(instance2.model_time,0.15 | units.yr, 3)
        instance2.evolve_model(0.3 | units.yr)
        print instance2.model_time.as_quantity_in(units.yr)
        self.assertAlmostRelativeEquals(instance2.model_time, 0.45| units.yr, 3)
        
        pos21 = quantities.as_vector_quantity(instance2.get_position(1))
        pos22 = quantities.as_vector_quantity(instance2.get_position(2))
        posmerger2 = quantities.as_vector_quantity(instance2.get_position(4))
        print pos11, pos21
        print pos12, pos22
        print posmerger1, posmerger2
        instance2.stop()
        
        self.assertAlmostRelativeEquals(pos11, pos21)
        self.assertAlmostRelativeEquals(pos12, pos22)
        self.assertAlmostRelativeEquals(posmerger1[0], posmerger2[0], 4)
        self.assertAlmostRelativeEquals(posmerger1[1], posmerger2[1], 1)
Beispiel #25
0
    def test12(self):
        convert_nbody=nbody_system.nbody_to_si(1.0|units.MSun, 1.0|units.yr/(2.0*pi))
        
        instance = Mikkola(convert_nbody)
        
        stars = datamodel.Stars(4)
        stars[0].mass = 1.0 | units.MSun
        stars[0].radius = 1.0| units.RSun
        stars[0].position = [0.0, 0, 0] | units.km
        stars[0].velocity = [0.0,0.0,0.0] | units.km/units.s

        stars[1].mass = 1.0 | units.MSun
        stars[1].radius = 1.0| units.RSun
        stars[1].position = [0.1, 0, 0] | units.RSun
        stars[1].velocity = [-0.4, 0.0, 0.0] | units.km/units.s
        
        stars[2].mass = 1.0 | units.MSun
        stars[2].radius = 1.0| units.RSun
        stars[2].position = [2, 0, 0] | units.RSun
        stars[2].velocity = [-0.1, 0.0, 0.0] | units.km/units.s
        
        stars[3].mass = 0.01 | units.MSun
        stars[3].radius = 1.0| units.RSun
        stars[3].position = [6000, 0, 0] | units.RSun
        stars[3].velocity = [0.0, -10, 0.0] | units.km/units.s
        
        
        instance.particles.add_particles(stars)
        
        instance.evolve_model(0.000001 | units.yr)
        instance.update_particle_set()
        self.assertEquals(instance.get_number_of_particles_added(), 1)
        self.assertEquals(instance.get_id_of_added_particle(0), 5)
        instance.evolve_model(0.30 | units.yr)
        self.assertEquals(instance.get_number_of_particles_added(), 1)
        self.assertEquals(instance.get_id_of_added_particle(0), 6)
        instance.update_particle_set()
        child1, child2 = instance.get_children_of_particle([5])
        self.assertEquals(child1[0], instance.particles[0])
        self.assertEquals(child2[0], instance.particles[1])
        child1, child2 = instance.get_children_of_particle([6])
        self.assertEquals(child1[0], instance.particles[2])
        self.assertEquals(child2[0], instance.particles[4])
Beispiel #26
0
    def test14(self):

        convert_nbody = nbody_system.nbody_to_si(1.0 | units.MSun,
                                                 1.0 | units.yr / (2.0 * pi))
        stars = datamodel.Stars(3)
        stars[0].mass = 1.0 | units.MSun
        stars[0].radius = 1.0 | units.RSun
        stars[0].position = [0.0, 0, 0] | units.km
        stars[0].velocity = [0.0, 0.0, 0.0] | units.km / units.s

        stars[1].mass = 1.0 | units.MSun
        stars[1].radius = 1.0 | units.RSun
        stars[1].position = [0.1, 0, 0] | units.RSun
        stars[1].velocity = [-0.4, 0.0, 0.0] | units.km / units.s

        stars[2].mass = 1e-9 | units.MSun
        stars[2].radius = 1.0 | units.RSun
        stars[2].position = [10000, 0, 0] | units.RSun
        stars[2].velocity = [0.0, -100, 0.0] | units.km / units.s

        instance = Mikkola(convert_nbody)
        instance.particles.add_particles(stars)
        instance.evolve_model(0.3 | units.yr)

        pos11 = quantities.as_vector_quantity(instance.get_position(1))
        pos12 = quantities.as_vector_quantity(instance.get_position(2))
        instance.stop()

        convert_nbody = nbody_system.nbody_to_si(1.0 | units.MSun,
                                                 1.0 | units.yr / (2.0 * pi))

        instance = Mikkola(convert_nbody)
        stars = datamodel.Stars(2)
        stars[0].mass = 1.0 | units.MSun
        stars[0].radius = 1.0 | units.RSun
        stars[0].position = [0.0, 0, 0] | units.km
        stars[0].velocity = [0.0, 0.0, 0.0] | units.km / units.s

        stars[1].mass = 1.0 | units.MSun
        stars[1].radius = 1.0 | units.RSun
        stars[1].position = [0.1, 0, 0] | units.RSun
        stars[1].velocity = [-0.4, 0.0, 0.0] | units.km / units.s

        instance.particles.add_particles(stars)
        self.assertRaises(exceptions.AmuseException, instance.evolve_model,
                          0.3 | units.yr)
        pos21 = quantities.as_vector_quantity(instance.get_position(1))
        pos22 = quantities.as_vector_quantity(instance.get_position(2))
        instance.stop()

        # positions will not be the same but distances will be comparable
        self.assertAlmostRelativeEquals((pos22 - pos21).length(),
                                        (pos12 - pos11).length(), 1)
Beispiel #27
0
    def test5(self):
        convert_nbody=nbody_system.nbody_to_si(1.0|units.MSun, 1.0|units.yr/(2.0*pi))
        
        instance = Mikkola(convert_nbody)
        
        stars = datamodel.Stars(3)
        stars[0].mass = 1.0 | units.MSun
        stars[0].radius = 1.0| units.RSun
        stars[0].position = [0.0, 0, 0] | units.km
        stars[0].velocity = [0.0,0.0,0.0] | units.km/units.s

        stars[1].mass = 1.0 | units.MSun
        stars[1].radius = 1.0| units.RSun
        stars[1].position = [0.1, 0, 0] | units.RSun
        stars[1].velocity = [-0.4, 0.0, 0.0] | units.km/units.s
        
        
        stars[2].mass = 0.01 | units.MSun
        stars[2].radius = 1.0| units.RSun
        stars[2].position = [6000, 0, 0] | units.RSun
        stars[2].velocity = [0.0, -10, 0.0] | units.km/units.s
        
        
        instance.particles.add_particles(stars)
        
        instance.evolve_model(0.25 | units.yr)
        
        self.assertEquals(instance.get_number_of_particles_added(), 1)
        self.assertRaises(Exception, instance.get_id_of_added_particle, [2])
        self.assertEquals(instance.get_id_of_added_particle(0), 4)
        self.assertAlmostRelativeEquals(instance.get_mass(4), 2 | units.MSun)
        self.assertAlmostRelativeEquals(instance.get_mass(1), 1 | units.MSun)
        self.assertAlmostRelativeEquals(instance.get_mass(2), 1 | units.MSun)
        pos1 = quantities.as_vector_quantity(instance.get_position(1))
        pos2 = quantities.as_vector_quantity(instance.get_position(2))
        posmerger = quantities.as_vector_quantity(instance.get_position(4))
        
        print pos1
        print pos2
        print posmerger
        distance = (pos1-pos2).length()
        self.assertTrue(distance < 1e-4 | units.RSun)
        self.assertTrue(distance > 1e-6 | units.RSun)
        distance = (pos1-posmerger).length()
        print distance.as_quantity_in(units.RSun)
        self.assertAlmostRelativeEquals(distance,0.718548184852 | units.RSun, 5)
        distance = (pos2-posmerger).length()
        print distance.as_quantity_in(units.RSun)
        self.assertAlmostRelativeEquals(distance,0.718548184852 | units.RSun, 5)
        instance.update_particle_set()
        print instance.particles[0].mass.as_quantity_in(units.MSun)
Beispiel #28
0
    def test12(self):
        convert_nbody = nbody_system.nbody_to_si(1.0 | units.MSun,
                                                 1.0 | units.yr / (2.0 * pi))

        instance = Mikkola(convert_nbody)

        stars = datamodel.Stars(4)
        stars[0].mass = 1.0 | units.MSun
        stars[0].radius = 1.0 | units.RSun
        stars[0].position = [0.0, 0, 0] | units.km
        stars[0].velocity = [0.0, 0.0, 0.0] | units.km / units.s

        stars[1].mass = 1.0 | units.MSun
        stars[1].radius = 1.0 | units.RSun
        stars[1].position = [0.1, 0, 0] | units.RSun
        stars[1].velocity = [-0.4, 0.0, 0.0] | units.km / units.s

        stars[2].mass = 1.0 | units.MSun
        stars[2].radius = 1.0 | units.RSun
        stars[2].position = [2, 0, 0] | units.RSun
        stars[2].velocity = [-0.1, 0.0, 0.0] | units.km / units.s

        stars[3].mass = 0.01 | units.MSun
        stars[3].radius = 1.0 | units.RSun
        stars[3].position = [6000, 0, 0] | units.RSun
        stars[3].velocity = [0.0, -10, 0.0] | units.km / units.s

        instance.particles.add_particles(stars)

        instance.evolve_model(0.000001 | units.yr)
        instance.update_particle_set()
        self.assertEqual(instance.get_number_of_particles_added(), 1)
        self.assertEqual(instance.get_id_of_added_particle(0), 5)
        instance.evolve_model(0.30 | units.yr)
        self.assertEqual(instance.get_number_of_particles_added(), 1)
        self.assertEqual(instance.get_id_of_added_particle(0), 6)
        instance.update_particle_set()
        child1, child2 = instance.get_children_of_particle([5])
        self.assertEqual(child1[0], instance.particles[0])
        self.assertEqual(child2[0], instance.particles[1])
        child1, child2 = instance.get_children_of_particle([6])
        self.assertEqual(child1[0], instance.particles[2])
        self.assertEqual(child2[0], instance.particles[4])
Beispiel #29
0
    def test4(self):
        convert_nbody = nbody_system.nbody_to_si(1.0 | units.MSun,
                                                 1.0 | units.yr / (2.0 * pi))
        instance = Mikkola(convert_nbody)

        stars = self.new_system_of_Hulse_Taylor_pulsar()
        instance.particles.add_particles(stars)

        instance.commit_particles()
        self.assertEqual(len(instance.particles), 2)
        instance.cleanup_code()
        self.assertEqual(len(instance.particles), 0)

        instance.initialize_code()
        instance.particles.add_particles(stars)
        self.assertEqual(len(instance.particles), 2)

        instance.commit_particles()
        self.assertEqual(len(instance.particles), 2)
        instance.cleanup_code()
        self.assertEqual(len(instance.particles), 0)
Beispiel #30
0
    def test8(self):
        convert_nbody = nbody_system.nbody_to_si(1.0 | units.MSun,
                                                 1.0 | units.yr / (2.0 * pi))

        stars = datamodel.Stars(3)
        stars[0].mass = 1.0 | units.MSun
        stars[0].radius = 1.0 | units.RSun
        stars[0].position = [0.0, 0, 0] | units.km
        stars[0].velocity = [0.0, 0.0, 0.0] | units.km / units.s

        stars[1].mass = 1.0 | units.MSun
        stars[1].radius = 1.0 | units.RSun
        stars[1].position = [0.1, 0, 0] | units.RSun
        stars[1].velocity = [-0.4, 0.0, 0.0] | units.km / units.s

        stars[2].mass = 0.01 | units.MSun
        stars[2].radius = 1.0 | units.RSun
        stars[2].position = [6000, 0, 0] | units.RSun
        stars[2].velocity = [0.0, -10, 0.0] | units.km / units.s

        instance1 = Mikkola(convert_nbody)
        instance1.particles.add_particles(stars)
        instance1.evolve_model(0.45 | units.yr)

        pos11 = quantities.as_vector_quantity(instance1.get_position(1))
        pos12 = quantities.as_vector_quantity(instance1.get_position(2))
        posmerger1 = quantities.as_vector_quantity(instance1.get_position(4))
        instance1.stop()

        instance2 = Mikkola(convert_nbody)
        instance2.particles.add_particles(stars)
        instance2.evolve_model(0.15 | units.yr)
        self.assertAlmostRelativeEquals(instance2.model_time, 0.15 | units.yr,
                                        3)
        instance2.evolve_model(0.3 | units.yr)
        print(instance2.model_time.as_quantity_in(units.yr))
        self.assertAlmostRelativeEquals(instance2.model_time, 0.45 | units.yr,
                                        3)

        pos21 = quantities.as_vector_quantity(instance2.get_position(1))
        pos22 = quantities.as_vector_quantity(instance2.get_position(2))
        posmerger2 = quantities.as_vector_quantity(instance2.get_position(4))
        print(pos11, pos21)
        print(pos12, pos22)
        print(posmerger1, posmerger2)
        instance2.stop()

        self.assertAlmostRelativeEquals(pos11, pos21)
        self.assertAlmostRelativeEquals(pos12, pos22)
        self.assertAlmostRelativeEquals(posmerger1[0], posmerger2[0], 4)
        self.assertAlmostRelativeEquals(posmerger1[1], posmerger2[1], 1)
Beispiel #31
0
    def test4(self):
        convert_nbody=nbody_system.nbody_to_si(1.0|units.MSun, 1.0|units.yr/(2.0*pi))
        instance = Mikkola(convert_nbody)

        stars = self.new_system_of_Hulse_Taylor_pulsar()
        instance.particles.add_particles(stars)
        
        instance.commit_particles()
        self.assertEquals(len(instance.particles), 2)
        instance.cleanup_code()
        self.assertEquals(len(instance.particles), 0)
        
        instance.initialize_code()
        instance.particles.add_particles(stars)
        self.assertEquals(len(instance.particles), 2)
        
        instance.commit_particles()
        self.assertEquals(len(instance.particles), 2)
        instance.cleanup_code()
        self.assertEquals(len(instance.particles), 0)