Exemple #1
0
    def test21(self):
        particles = datamodel.Particles(2)
        particles.x = [0.0,10.0] | nbody_system.length
        particles.y = 0.0 | nbody_system.length
        particles.z = 0.0 | nbody_system.length
        particles.radius = 0.005 | nbody_system.length
        particles.vx =  0.0 | nbody_system.speed
        particles.vy =  0.0 | nbody_system.speed
        particles.vz =  0.0 | nbody_system.speed
        particles.mass = 1.0 | nbody_system.mass

        very_short_time_to_evolve = 1 | units.s
        very_long_time_to_evolve = 1e9 | nbody_system.time
       
        instance = FDPS()
        instance.initialize_code()
        instance.parameters.epsilon_squared = (1e-5 | nbody_system.length)**2
        instance.particles.add_particles(particles)     
        instance.commit_particles()
        self.assertAlmostRelativeEquals(instance.potential_energy, -0.1 | nbody_system.energy, 5)
        instance.stop()
Exemple #2
0
    def test15(self):
        print "Test15: Testing effect of FDPS parameter epsilon_squared"
        convert_nbody = nbody_system.nbody_to_si(1.0 | units.MSun, 1.0 | units.AU)
        
        particles = datamodel.Particles(2)
        sun = particles[0]
        sun.mass = 1.0 | units.MSun
        sun.position = [0.0, 0.0, 0.0] | units.AU
        sun.velocity = [0.0, 0.0, 0.0] | units.AU / units.yr
        sun.radius = 1.0 | units.RSun

        earth = particles[1]
        earth.mass = 5.9736e24 | units.kg
        earth.radius = 6371.0 | units.km
        earth.position = [0.0, 1.0, 0.0] | units.AU
        earth.velocity = [2.0*numpy.pi, -0.0001, 0.0] | units.AU / units.yr
        
        initial_direction = math.atan((earth.velocity[0]/earth.velocity[1]))
        final_direction = []
        for log_eps2 in range(-9,10,2):
            instance = FDPS(convert_nbody)
            instance.initialize_code()
            instance.parameters.epsilon_squared = 10.0**log_eps2 | units.AU ** 2
            instance.parameters.timestep = 0.005 | units.yr
            instance.particles.add_particles(particles)
            instance.commit_particles()
            instance.evolve_model(0.25 | units.yr)
            final_direction.append(math.atan((instance.particles[1].velocity[0]/
                instance.particles[1].velocity[1])))
            instance.stop()
        # Small values of epsilon_squared should result in normal earth-sun dynamics: rotation of 90 degrees
        self.assertAlmostEquals(abs(final_direction[0]), abs(initial_direction+math.pi/2.0), 2)
        # Large values of epsilon_squared should result in ~ no interaction
        self.assertAlmostEquals(final_direction[-1], initial_direction, 2)
        # Outcome is most sensitive to epsilon_squared when epsilon_squared = d(earth, sun)^2
        delta = [abs(final_direction[i+1]-final_direction[i]) for i in range(len(final_direction)-1)]
        self.assertEquals(delta[len(final_direction)//2 -1], max(delta))
Exemple #3
0
 def test16(self):
     numpy.random.seed(0)
     number_of_stars = 2
     stars = plummer.new_plummer_model(number_of_stars)
     stars.radius = 0.00001 | nbody_system.length
     stars.scale_to_standard()
     
     instance = FDPS()
     instance.initialize_code()
     instance.parameters.epsilon_squared = (1.0 / 20.0 / (number_of_stars**0.33333) | nbody_system.length)**2
     instance.parameters.timestep = 0.004 | nbody_system.time
     instance.parameters.timestep = 0.00001 | nbody_system.time
     instance.commit_parameters()
     print instance.parameters.timestep
     instance.particles.add_particles(stars)
     instance.commit_particles()
     energy_total_t0 = instance.potential_energy + instance.kinetic_energy
     request = instance.evolve_model.async(1.0 | nbody_system.time)
     request.result()
     energy_total_t1 = instance.potential_energy + instance.kinetic_energy
     
     self.assertAlmostRelativeEqual(energy_total_t0, energy_total_t1, 3)
     instance.stop()
     numpy.random.seed()